How Can You Handle Unassigned Outputs in Simulink's Embedded MATLAB Function?

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 5K views
ilconformista
Messages
18
Reaction score
0
Hello everyone!
In Simulink , I use the Embedded MATLAB Function

function out = fcn(meas)

if meas>10
out = 4;
elseif meas<=0
out=2;
end

And I get this message:
Output argument 'out' is not assigned on some execution paths.

I would like the variable 'out' to change its value only if either of these conditions is true.
So I guess I have to give 'out' an initial value that is valid only for the first cycle of the program.
Does anyone know how I can do that?

Thanks!
 
Physics news on Phys.org
ilconformista said:
I would like the variable 'out' to change its value
What will the function return if meas is in 0<meas<=10? You have to specify an else with the if-else, because the variable would otherwise not be defined when the two conditions you have given are not satisfied, and the function would have nothing to return.