正在加载图片...
plot(x(i)y(i),”g") elseif y(i)>=-1 y(i) plot(x(i)y(i),’ob") elseif y(i>=l plot(x(i)y(i),’xr) d en hold off (3)分支语句: switch-case-end 通过对某个变量值的比较做各种不同的执行选择。 形式: switch表达式(数字或字符串) case数字或字符串1 语句体1; case数字或字符串2 语句体2 otherwise 语句体n end 例:检查 input num的数值 switch input num dip( negative one);%当 input num=1时显示 case 0 disp(zero); %当 input num=0时显示 case 1 disp( positive one);%当 input num=1时显示plot(x(i),y(i),'*g') elseif y(i)>=-1 & y(i)<=1 plot(x(i),y(i),'ob') elseif y(i)>=1 plot(x(i),y(i),'xr') end end hold off (3) 分支语句:switch—case—end 通过对某个变量值的比较做各种不同的执行选择。 形式: switch 表达式(数字或字符串) case 数字或字符串 1 语句体 1; case 数字或字符串 2 语句体 2; …… otherwise 语句体 n; end 例:检查 input_num 的数值. switch input_num case -1 disp(‘negative one’); %当 input_num=-1 时显示 case 0 disp(‘zero’); %当 input_num= 0 时显示 case 1 disp(‘positive one’); %当 input_num= 1 时显示
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有