作业帮 > 综合 > 作业

关于matlab的switch语句,请帮我找找错误

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/15 14:07:29
关于matlab的switch语句,请帮我找找错误
price = input('input price');
switch fix(price/100)
case [0, 1]
rate = 0;
case [2, 3, 4]
rate = 0.03;
case [5, 6, 7, 8, 9]
rate = 0.05;
otherwise
rate = 0.1;
end
为什么无论我输入什么数字结果都是0.1?
clear;
clc;
price = input('input price:');
switch fix(price/100)
case {0, 1}
rate = 0;
case {2, 3, 4}
rate = 0.03;
case {5, 6, 7, 8, 9}
rate = 0.05;
otherwise
rate = 0.1;
end
rate
注意:使用{} 不用[]
结果示例:
input price:350
rate =
0.0300