Why are initial input values zero for Interpreted MATLAB Fcn block?
Show older comments
When using an Interpreted MATLAB Fcn block, I noticed that when I run the simulation, on the first call to the function the inputs are set to zero, regardless of their actual values. For instance the value might be supplied by a constant set equal to 1, but on the first call to Interpreted function block, its value will be zero.
I have attached a simple example to demonstrate the problem. The function, myfun(u), called by the interpreted function block, assigns an output value equal to the input.
function out = myfun(u)
out = u
Note that in the attached example, even though the input to the interpreted function block is assigned a value of 1, by the constant block, when you run the simulation, the first output (printed to the command window) will infact be 0, and after that is correctly computed to be equal to 1.
You can also see this if you put a breakpoint with the debugger inside of myfun. The Simulation stops in the Compilation Phase (probably a clue as to why the inputs aren't assigned yet) and the inputs can be seen to be zero.
If anyone can please explain further what is going on and/or how to avoid this problem (It can cause issues with functions failing due to trying to compute outputs when all inputs are assigned to zero) I would appreciate it. I don't remember having problems with this before. Is this something new, or did I just never notice it?
By the way, I do see that interpreted MATLAB functions will soon be deprecated, but I have some legacy code that still uses them.
Accepted Answer
More Answers (0)
Categories
Find more on Signal Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!