I have 'value' as a cell array (Size 160*1) contians S101,S100,S103, S102 randomly.I need to look for S100 followed by S102 in this cell array such that if t1 == 'S100' && t2 == 'S102'. How can I do that?

1 回表示 (過去 30 日間)
for j = 1:(length(value)-1)
t1 = value(j);
t2 = value(j+1);
if ~ strcmp {t1 , 'S100'} && strcmp {t2, 'S102'}
This doesn't work.

採用された回答

Geoff Hayes
Geoff Hayes 2018 年 6 月 21 日
編集済み: Geoff Hayes 2018 年 6 月 21 日
Bubblesjinx - if t1 and t2 are character arrays, then your condition would be
if strcmp(t1, 'S100') && strcmp(t2, 'S102')
% do something
end
Use brackets instead of the braces {}.
To ensure that t1 and t2 are character arrays and not cells, then do
t1 = value{j};
t2 = value{j+1};
Note that how we index into cell arrays (using brackets or braces) determines the type of the retrieved element. Using brackets will give us a cell; using braces will give us the "native" data type of the object in that cell.
  1 件のコメント
Bubblesjinx
Bubblesjinx 2018 年 6 月 21 日
Thanks I was using if ~ strcmp (t1, 'S100') && strcmp (t2, 'S102')
removed ~ and it worked :) Thanks a lot

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by