Azzera filtri
Azzera filtri

combining multiple or statements

3 visualizzazioni (ultimi 30 giorni)
shru s
shru s il 12 Lug 2017
Commentato: shru s il 12 Lug 2017
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

Risposta accettata

Rik
Rik il 12 Lug 2017
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 Commenti
shru s
shru s il 12 Lug 2017
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 il 12 Lug 2017
ive got it. thank you :)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by