필터 지우기
필터 지우기

combining multiple or statements

조회 수: 3 (최근 30일)
shru s
shru s 2017년 7월 12일
댓글: shru s 2017년 7월 12일
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..
shru s
shru s 2017년 7월 12일
ive got it. thank you :)

댓글을 달려면 로그인하십시오.

추가 답변 (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