I guess, you are trying to run the loop for checking Moisture_Sensor_area_1_OUT<Moisture_instruction_min condition for every sample time.
But Simulink's Matlab Function runs in different way. It is invoked at every sample time during model execution.
At t=0, Get the 3 function inputs from previous blocks, Call fcn with inputs, collect fcn output and send to next block
At t=1, Get the 3 function inputs from previous blocks, Call fcn with inputs, collect fcn output and send to next block
At t=2, Get the 3 function inputs from previous blocks, Call fcn with inputs, collect fcn output and send to next block
...
... and so on.
Inputs to fcn remains same during the a sample time, so loop will always run into infinity.
You don't need to use while loop. You can just use if condition to set output.
2 Comments
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/422360-infinite-while-loop-in-matlab-function-block#comment_618142
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/422360-infinite-while-loop-in-matlab-function-block#comment_618142
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/422360-infinite-while-loop-in-matlab-function-block#comment_618196
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/422360-infinite-while-loop-in-matlab-function-block#comment_618196
Sign in to comment.