Can't identify the condition under which the variable is not defined in a function
1 view (last 30 days)
Show older comments
Sreerag Kunnathu Sugathan
on 25 Dec 2015
Commented: Walter Roberson
on 25 Dec 2015
The following is a code that is written for certain function I need inside the matlab function in simulink. a1,b1,c1 are the values that are being updated from outside the function block. These values will get updated according to the output y of the function block. When the code is run a message is being shown. "y is not assigned on certain paths". But I can't seem to find such a condition under which y is not defined.
0 Comments
Accepted Answer
Walter Roberson
on 25 Dec 2015
Your while is an infinite loop if any B(i) < 20.
The analysis is noticing that y is only assigned if there is at least one loop of the "for", but the analysis is not strong enough to prove that n is positive (because B must not be empty because that would require u to have been empty and that would have created an error before you got there.)
In cases like this, just initialize the output variable before the for loop.
2 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements 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!