matlab 中 switch 的例子
来源:学生作业帮 编辑:搜搜做题作业网作业帮 分类:综合作业 时间:2024/05/08 07:14:13
matlab 中 switch 的例子
Programming in MATLAB: Switch/Case Statement - Code
x = 3.0; % numeric variable
units = 'mm'; % string variable
switch units
case {'in','inch'} % multiple matches
y = 2.54*x; % converts to centimeters
disp ([num2str(x) ' ' units ' converted to cm is :' num2str(y)])
% disp is used to print pretty in the command window
% in the above a string vector is being printed
case {'m','meter'}
y = x*100; % converts to centimeters
disp ([num2str(x) ' ' units ' converted to cm is :' num2str(y)])
case { 'millimeter','mm'}
y = x/10;
disp ([num2str(x) ' ' units ' converted to cm is :' num2str(y)])
case {'cm','centimeter'}
y = x;
disp ([num2str(x) ' ' units ' converted to cm is :' num2str(y)])
otherwise
disp (['unknown units:' units])
y = nan; % not a number
end
x = 3.0; % numeric variable
units = 'mm'; % string variable
switch units
case {'in','inch'} % multiple matches
y = 2.54*x; % converts to centimeters
disp ([num2str(x) ' ' units ' converted to cm is :' num2str(y)])
% disp is used to print pretty in the command window
% in the above a string vector is being printed
case {'m','meter'}
y = x*100; % converts to centimeters
disp ([num2str(x) ' ' units ' converted to cm is :' num2str(y)])
case { 'millimeter','mm'}
y = x/10;
disp ([num2str(x) ' ' units ' converted to cm is :' num2str(y)])
case {'cm','centimeter'}
y = x;
disp ([num2str(x) ' ' units ' converted to cm is :' num2str(y)])
otherwise
disp (['unknown units:' units])
y = nan; % not a number
end
matlab 中 switch 的例子
Matlab switch 的应用举例.
matlab switch 语句:
matlab switch怎么使用?
matlab的switch case可以用矩阵么
关于matlab的switch语句,请帮我找找错误
关于c中switch的应用
在switch语句中continue的含义
初学Matlab,有两个语句,if语句和switch语句,有两个例子哪位大神能帮我讲讲
有一串数字(成绩),用matlab中switch语句统计分段人数,并将个人的成绩变为优良中和不及格,统计人数和成绩都用子
请问for循环中,switch里的break,跳出switch后,还继续for循环吗?
用matlab中的switch语句编程实现运输费用的计算: