Matlab Function, switch case Problem
4 ビュー (過去 30 日間)
古いコメントを表示
I am writing a Matlab Function, using the switch case, in order to be able to determine multiple conditions and output the corresponding value, but when time is equal to 0.3, the simulation will not output the value of this step, it is always skipped. why is this happening? My simulation step size is set to a fixed step size and the step size is 0.1. The input of the function is the clock.
Programm:
function y = fcn(u)
switch u
case 0.1
y=1;
case 0.2
y=2;
case 0.4
y=3;
case 0.3
y=4;
otherwise
y=6;
end
0 件のコメント
採用された回答
Fangjun Jiang
2020 年 11 月 9 日
This is a floating-point data equal or non-equal comparision problem. Do this to get an idea.
>> 1-1/3==2/3
ans =
logical
0
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Event Functions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!