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

조회 수: 2 (최근 30일)
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 |.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by