我的单元格描述如下:
mixed_values = {'jim', 89, [5 2 1; 1 2 3]};
mixed_values{1}
mixed_values{2}
mixed_values{3}
我循环它:
for k=1:length(mixed_values)
curstate=mixed_values{k};
% Check for the [5 2 1; 1 2 3]
if ismatrix(curstate)
disp('yes');
else
disp('no')
end
end
但是它多次发现矩阵。
yes
yes
yes
怎么检查呢?
从Matlab帮助:
如果SIZE(M)返回具有非负整数值m和n的[mn],则ismatrix(M)返回逻辑1(真),否则返回逻辑0(假)
所以我检查了 size(curstate)
1 3 % 3 character string array
1 1 % of course you can do size of a single elements
2 3
所以我修改了你的代码
for k=1:length(mixed_values)
curstate=mixed_values{k};
% Check for the [5 2 1; 1 2 3]
if (size(curstate,1)) > 1 && (size(curstate,2)) > 1
disp('yes');
disp(size(curstate));
else
disp('no')
end
end
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句