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

1 回表示 (過去 30 日間)
Armindo
Armindo 2019 年 2 月 7 日
編集済み: Armindo 2019 年 2 月 7 日
Names = {'RHip','RKnee','RAnkle'};
Why doing this works ok
if~isempty( strfind(Names{1}, 'Hip') || strfind(Names{2}, 'Knee'))
if~isempty( strfind(Names{1}, 'Hip') || strfind(Names{3}, 'Knee'))
but doing this gives the error Operands to the || and && operators must be convertible to logical scalar values.
if~isempty( strfind(Names{3}, 'Hip') || strfind(Names{2}, 'Knee'))
Note in code was missing the ~isempty (i already added it). Nevertheless this dont change the outcome. The problem is that when the first operation give an [ ] the outcome is an error

採用された回答

Walter Roberson
Walter Roberson 2019 年 2 月 7 日
strfind can return empty and you cannot use && or || with empty .
strfind finds all occurrences and returns their index . It is not intended to directly answer the question of whether to pattern occurs somewhere Yes or No. With new enough MATLAB use contains()

その他の回答 (1 件)

Armindo
Armindo 2019 年 2 月 7 日
Thanks but that don't solve the problem. The code doesn't work with || neither with |.
  1 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 2 月 7 日
編集済み: KALYAN ACHARJYA 2019 年 2 月 7 日
Please read the explanation form @Walter sir

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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by