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.
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!