How to change Matlab function block interpretation of inputs?

2 ビュー (過去 30 日間)
Stefan
Stefan 2015 年 8 月 7 日
コメント済み: Sebastian Castro 2015 年 8 月 11 日
Dear reader,
I have a question in Simulink, regarding MATLAB Function block. In this scheme
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,

回答 (1 件)

Sebastian Castro
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 件のコメント
Stefan
Stefan 2015 年 8 月 7 日
編集済み: Stefan 2015 年 8 月 10 日
Thank you for your answer. You say that by default, when a block's input port is unconnected, Simulink assumes a zero is passed in. This allows me to reformulate my original question:
A solution might be to alter Simulink's default interpretation into a non-numeric value or NaN, but how to do it?
How can I make the MATLAB Function block "feel" the difference between the two situations where: (i) I have nothing connected to the input block, and (ii) I really provide a connected constant to the input port, and this constant is zero? In my understanding Simulink interprets both situations as having the numeric value zero as input, whereas they should be treated differently for what I need :(
Thanks.
Sebastian Castro
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 ExchangeSources についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by