How to write an if statement that returns which of the conditions is met
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Matlab_Student
il 23 Gen 2018
Risposto: Walter Roberson
il 23 Gen 2018
I have the following psuedocode:
if (cond1) or (cond2)
print('1');
end
Now I would like it to tell which of the two conditions are met or both of them are met by printing the corresponding conditions. How would I accomplish this?
0 Commenti
Risposta accettata
Walter Roberson
il 23 Gen 2018
Provided cond1 and cond2 are scalar logical values:
(cond1) + 2 * (cond2)
This returns 1 if cond1 but not cond2, returns 2 if cond2 but not cond1, and returns 3 if both of them are true.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su MATLAB Mobile in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!