Trouble using strings in If statements using OR

15 vues (au cours des 30 derniers jours)
Sarah R
Sarah R le 20 Jan 2022
Commenté : Stephen23 le 21 Jan 2022
I am trying to loop through and use IF statement as example:
if race == "H2" | "H1" | "H3" | "H4"
but I get error "Error using |
Input must be text or pattern."
If I try: race == "H2" || "H1" || "H3" || "H4"
I get error:
Conversion to logical from string is not possible.
"H1" and so forth are strings in Matlab
Thank you!

Réponse acceptée

Voss
Voss le 20 Jan 2022
if race == "H2" || race == "H1" || race == "H3" || race == "H4"
  1 commentaire
Walter Roberson
Walter Roberson le 20 Jan 2022
Or alternately
if ismember(race, ["H1", "H2", "H3", "H4"])

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by