matlab switch case 不太会用,程序一直有错.clc;clear;x=0:0.1*pi:2*pi;a=input('name:')switch acase 'sin'y=sin(x);plot(x,y)case 'cos'y=cos(x);plot(x,y)case 'tan'y=tan(x);plot(x,y)otherwisebreak;end

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/23 03:05:43
matlabswitchcase不太会用,程序一直有错.clc;clear;x=0:0.1*pi:2*pi;a=input(''name:'')switchacase''sin''y=sin(x);plot(

matlab switch case 不太会用,程序一直有错.clc;clear;x=0:0.1*pi:2*pi;a=input('name:')switch acase 'sin'y=sin(x);plot(x,y)case 'cos'y=cos(x);plot(x,y)case 'tan'y=tan(x);plot(x,y)otherwisebreak;end
matlab switch case 不太会用,程序一直有错.
clc;
clear;
x=0:0.1*pi:2*pi;
a=input('name:')
switch a
case 'sin'
y=sin(x);
plot(x,y)
case 'cos'
y=cos(x);
plot(x,y)
case 'tan'
y=tan(x);
plot(x,y)
otherwise
break;
end

matlab switch case 不太会用,程序一直有错.clc;clear;x=0:0.1*pi:2*pi;a=input('name:')switch acase 'sin'y=sin(x);plot(x,y)case 'cos'y=cos(x);plot(x,y)case 'tan'y=tan(x);plot(x,y)otherwisebreak;end
不是case的问题,你这里case的用法没有问题
是输入语句的问题,应该改为
a=input('name:','s');
多一个参数's'表面输入的内容是字符串,就好了