How to change Matlab function block interpretation of inputs?
조회 수: 2 (최근 30일)
이전 댓글 표시
Dear reader,
I have a question in Simulink, regarding MATLAB Function block. In this scheme
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/147838/image.png)
I've put inside the MATLAB Function block the code
y = u;
What I find strange is that when running this file, the Display shows zero whereas I would have expected to see a NaN. How did it get to set this default value? Is there a way to change default interpretation of non-linked (i.e. not connected via black arrow) inputs to MATLAB Function?
Thank you,
댓글 수: 0
답변 (1개)
Sebastian Castro
2015년 8월 7일
By default, when you leave a block's input port unconnected, Simulink assumes a zero (with the right data type and dimensions for the block) is passed in.
If you really want to see a NaN, you can connect a Constant block to the input and set its value to NaN.
I guess the question is, what exactly are you trying to do with this model? If you plan on eventually connecting a periodic signal to the input of the block, then this shouldn't matter. However, if your plan is to implement some kind of "event-based" logic where the initial output is NaN, you could initialize your output to NaN using persistent variables, then overwrite the value as soon as you get a numerical value in from the input port.
- Sebastian
댓글 수: 2
Sebastian Castro
2015년 8월 11일
I don't think you can change that behavior. Why do you need it, though? Maybe there's a different way to think about it which is possible to do with the tool.
참고 항목
카테고리
Help Center 및 File Exchange에서 Simulink Functions에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!