gpt4 book ai didi

matlab:将百分制改为五分制

转载 作者:行者123 更新时间:2023-12-02 02:26:35 25 4
gpt4 key购买 nike

matlab中的switch case问题
将百分制改为五分制。

function f=fjou(x)

switch x
case x>=90
f='5';
case x>=80&x<90
f='4';
case x>=70&x<80
f='3';
case x>=60&x<70
f='2';
otherwise
f='1';
end

如果参数>60,结果总是“1”,为什么?

最佳答案

您正在像使用一系列 if...elseif...elseif...else 一样使用 switch 语句。 switch 的工作方式是 switch 的参数必须匹配大小写。这是一个使用 switch 语句执行您正在查找的操作的示例。

switch floor(x/10)
case 10,
f='5';
case 9,
f='5';
case 8,
f='4';
case 7,
f='3';
case 6,
f='2';
otherwise
f='1';

结束

关于matlab:将百分制改为五分制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5648906/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com