フィルターのクリア

Make a logical loop with string?

1 回表示 (過去 30 日間)
Ivan Shorokhov
Ivan Shorokhov 2015 年 1 月 14 日
コメント済み: Ivan Shorokhov 2015 年 1 月 14 日
Hello,
I would like to make "if" loop by using strings. So if the string is: 'Cor' or 'Sag', do main_LA, else if the string is:'Tra' do main_SA;
if DI.Orientation == strcomp('Cor'|| 'Sag')
main_LA;
else DI.Orientation == 'Tra'
main_SA;
end
Is that the right way of doing it? Thanks, I

採用された回答

Geoff Hayes
Geoff Hayes 2015 年 1 月 14 日
Ivan - your use of strcmp is not quite correct. To compare whether the orientation is either Cor or Sag, you would need to do the following
if strcmp(DI.Orientation,'Cor') || strcmp(DI.Orientation,'Sag')
main_LA;
elseif strcmp(DI.Orientation,'Tra')
main_SA;
end
The above assumes that orientation is one of the above three strings. If you wish to ignore case (upper or lower), the use strcmpi.
  1 件のコメント
Ivan Shorokhov
Ivan Shorokhov 2015 年 1 月 14 日
Thank you very much!

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

その他の回答 (0 件)

カテゴリ

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