MATLAB Answers

Error: Operands to the || and && operators must be convertible to logical scalar values.

4 views (last 30 days)
Zeynab Mousavikhamene
Zeynab Mousavikhamene on 14 Jan 2020
Edited: Fangjun Jiang on 14 Jan 2020
I need to say:
if ((YesNo=='Yes') ||(YesNo=='yes'))
if YesNo was 'Yes' or 'yes' then do sth. but I recieve error shown in the title.

  0 Comments

Sign in to comment.

Answers (1)

Fangjun Jiang
Fangjun Jiang on 14 Jan 2020
use strcmpi()

  2 Comments

Fangjun Jiang
Fangjun Jiang on 14 Jan 2020
YesNo=='Yes' returns a 1x3 array, or a vector
"||" can only be applied to logical scalar values
you could use (YesNo=='Yes') | (YesNo=='yes'), or call the or() function, or(YesNo=='Yes', YesNo=='yes'), but that still returns a vector.
help relop

Sign in to comment.

Sign in to answer this question.


Translated by