combining multiple or statements

3 次查看(过去 30 天)
hello, i wish to combine this or statement in in one line
switch m
case m==1|2|3|4|5|6|7|8|9|10
disp('A');
end
Is this possible? I do not want to type 1 2 3 4 etc because i have a lot of values to type in. Thank you

采纳的回答

Rik
Rik 2017-7-12
As the documentation for switch suggests, making a cell array enables you to check multiple conditions at once. You can open the documentation by typing doc switch or by using Google.
m=3;
switch m
case {1,2,3,4}
disp('boo!')
otherwise
disp('ah!!')
end
You can also use a variable instead of typing them out.
m=3;
c=num2cell(1:10);
switch m
case c
disp('boo!')
otherwise
disp('aw..')
end
  2 个评论
shru s
shru s 2017-7-12
Brilliant! Thank you so much! :) if i run it for three loops and i get boo! boo! aw.. is the 1st 2nd and 3rd loop respectively, is there a way i can concatenate them together and display them? like boo!boo!aw..

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by