How do I avoid the error : " assign output variable x0 for example has not been assigned a value" ?
Show older comments
I'm having problems getting this code to run. How do I ensure values are assigned for both inputs and outputs to have a successfully generated code?
Answers (1)
Walter Roberson
on 13 Nov 2022
Edited: Walter Roberson
on 13 Nov 2022
If you are looking at function sf_bioc then it only assigns a value to x0 in the case that flag == 0. Code generation needs there to be an assignment to the function in all cases. The easiest way to do that is to move the assignment to x0 to outside of the if statement.
Side note:
if abs(flag == 1)
is odd code. logical comparisons can never return negative numbers, so abs() of them is pointless except in-so-far as it effectively converts the logical to double.
I would understand if the code had been
if abs(flag) == 1
though I do not know at the moment whether the flag value can be -1 ever.
3 Comments
Ryan Fraser
on 13 Nov 2022
Walter Roberson
on 13 Nov 2022
Is the error about not enough input arguments at the time you are doing code generation? If so then how are you doing code generation ?
Ryan Fraser
on 13 Nov 2022
Categories
Find more on Calendar 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!