if statements not executing as expected
8 views (last 30 days)
Show older comments
I'm experiencing problems with if statements under certain conditions. I'm using code within a Simulink embedded Matlab function block that looks something like this:
function setting = setting_select(error)
if error == -0.1
setting = 3;
else
setting = 4;
end
This looks trivial but the setting = 3 statement never executed even if error does indeed equal -0.1. The error signal is computed in a separate embedded Matlab block. However, when I replace the error signal with a constant (-0.1) the statement executes correctly. There are no algebraic loops nor continuous states in the model. I've tried casting data types in case the conditional statement is comparing different number formats but that didn't work either.
Thanks for your help.
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!