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 visualizaciones (últimos 30 días)
for j = 1:(length(value)-1)
t1 = value(j);
t2 = value(j+1);
if ~ strcmp {t1 , 'S100'} && strcmp {t2, 'S102'}
This doesn't work.

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 21 de Jun. de 2018
Editada: Geoff Hayes el 21 de Jun. de 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.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by