Equal Cell
96 次查看(过去 30 天)
显示 更早的评论
Hallo,
how can i use condition "if", if i have two variables type cell? For examlpe:
if(datLab(k)==label(i))
disp(datLab(k));
else
disp('No exist');
end
end
datLab and label are variables cell (string).
Thanks
0 个评论
采纳的回答
更多回答(1 个)
Laura Proctor
2011-3-18
To get the contents of a cell, use the curly braces. For example:
v1 = {2};
v2 = {2};
if v1{1} == v2{1}
disp(['v1 = v2 = ',num2str(v1{1})])
else
disp('not equal')
end
1 个评论
Walter Roberson
2011-3-18
The original poster indicated that the values are strings; using == to compare strings does not work unless the strings are exactly the same length. strcmp() or isequal() do not have that difficulty.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!