Matlab Function, switch case Problem

조회 수: 8 (최근 30일)
Taihao Li
Taihao Li 2020년 11월 9일
댓글: Taihao Li 2020년 11월 12일
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.
Result graph
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

채택된 답변

Fangjun Jiang
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
  댓글 수: 1
Taihao Li
Taihao Li 2020년 11월 12일
I understand, the model can work normally after I changed the conditions, thanks for your help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linearization에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by