Simulink 中的案例陈述
我只是无法弄清楚如何继续:
我正在尝试构建一个模型:
- 它将有 4 个输入(布尔 i/p)
- 它将有 1 个输出(签名:8 位)
它将执行以下操作:
- 基于输入为 1 时,它将给出反映 DataRate 的相应输出。
如果我必须在 Matlab 中编写,我会写这样的内容:
if (portA==1)
PSDU_Data_Rate=1;
elseif(portB==1)
PSDU_Data_Rate=2;
elseif (portC==1)
PSDU_Data_Rate=5.5;
elseif(portD==1)
PSDU_Data_Rate=11;
end
我正在附加我正在为相同功能开发的模型部分:
任何有关如何进行或代码更正或如何改进的建议的想法都会非常有帮助。
谢谢
I am just not able to figure out how to proceed:
I am trying to build a model:
- It would have 4 Inputs ( Boolean i/p)
- It would have 1 output (Signed: 8 bit)
It would perform the following:
- Based on which input is 1, it would give a corresponding output reflecting the DataRate.
If I have to write in Matlab, I would write something like this :
if (portA==1)
PSDU_Data_Rate=1;
elseif(portB==1)
PSDU_Data_Rate=2;
elseif (portC==1)
PSDU_Data_Rate=5.5;
elseif(portD==1)
PSDU_Data_Rate=11;
end
I am attaching, the part of the model which I am developing for the same functionality:
Any idea on how to proceed or code correction or suggestion on how it can be improved would be really helpful.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您有 4 个不同的输入,而不是一个带有枚举值的输入,因此请使用 If - Else,而不是 Case 语句。我正在添加如何完成此操作的屏幕截图。请注意,如果您想默认选择一种数据速率(如果没有输入非零),则 If 模块还允许您有 Else 输出。
If
块设置:该模型由一个连接到一组
If Action Subsystem
块的If
块组成。后者的输出可以使用Merge
块组合成单个信号。Since you have 4 distinct inputs instead of a single input carrying an enumerated value, use If - Else, instead of a Case statement. I'm adding screenshots of how this can be done. Note that the If block also lets you have an Else output if you want to select one of the data rates by default (if none of the inputs are non-zero).
If
block settings:The model consists of an
If
block connected to a set ofIf Action Subsystem
blocks. The outputs of the latter can be combined into a single signal using aMerge
block.