MATLAB: Do I receive error messages when updating the model that contains Embedded MATLAB blocks in Simulink

MATLABpersistentsimulinkvariablevariables

When I update the Simulink model, I receive an error on the Embedded MATLAB block:
Persistent variable previous_stage must be unambiguously written to before use.
and also:
Output Input_ref must be assigned before returning from the function.

Best Answer

This error occurs because you have not properly assigned values to the persistent variables that present in the Embedded MATLAB block.
The way to assign values to "previous_stage" and "previous_step" persistent variables is to use the following code:
if isempty(previous_stage)
previous_stage = 0;
end
if isempty(previous_step)
previous_step = 0;
end