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?

2 views (last 30 days)
for j = 1:(length(value)-1)
t1 = value(j);
t2 = value(j+1);
if ~ strcmp {t1 , 'S100'} && strcmp {t2, 'S102'}
This doesn't work.

Accepted Answer

Geoff Hayes
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.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!