Infinite while loop in Matlab function block
4 ビュー (過去 30 日間)
古いコメントを表示
I have made this programm to implemente it in a Matlab function block in Simulink :
function Open_area1 = fcn(Moisture_Sensor_area_1_OUT,Moisture_instruction_min,Moisture_instruction_max)
Open_area1 = 0;
if (Moisture_Sensor_area_1_OUT<Moisture_instruction_min)
while(Moisture_Sensor_area_1_OUT<Moisture_instruction_max)
Open_area1 = 1;
end
end
end
But the while loop make an infinite simulation time.
2 件のコメント
KALYAN ACHARJYA
2018 年 10 月 5 日
That means the following condition is always true
Moisture_Sensor_area_1_OUT<Moisture_instruction_max
Do same sort of modification (update), so that it not true after some required iteration
採用された回答
Walter Roberson
2018 年 10 月 8 日
Output = double(Input >= Min & Input <= Max) ;
No loop. No if. But you do need to substitute appropriate variables.
0 件のコメント
その他の回答 (1 件)
TAB
2018 年 10 月 8 日
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Simulink Functions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!