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

1 回表示 (過去 30 日間)
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2020 年 1 月 14 日
編集済み: Fangjun Jiang 2020 年 1 月 14 日
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.

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2020 年 1 月 14 日
use strcmpi()
  2 件のコメント
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2020 年 1 月 14 日
Thank you but I am interested to know what is wrong with this or logical.
Fangjun Jiang
Fangjun Jiang 2020 年 1 月 14 日
編集済み: Fangjun Jiang 2020 年 1 月 14 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by