# 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 view (last 30 days)
Bubblesjinx on 21 Jun 2018
Commented: Bubblesjinx on 21 Jun 2018
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 on 21 Jun 2018
Edited: Geoff Hayes on 21 Jun 2018
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.
Bubblesjinx on 21 Jun 2018
Thanks I was using if ~ strcmp (t1, 'S100') && strcmp (t2, 'S102')
removed ~ and it worked :) Thanks a lot