我认为我的问题可能很常见,但我找不到答案。也许我正在以错误的方式看待这个!?我怎样才能从这种类型的矩阵中制作一个图例:
X =
[4.4200e+09] [ 600] [ 8] 'm2 hard hm (50)'
[4.4200e+09] [ 600] [ 8] 'm3 hard hm (52)'
[4.4200e+09] [ 600] [ 8] 'm2 soft hm (56)'
[4.4200e+09] [ 600] [ 8] 'm3 soft hm (58)'
[4.4200e+09] [ 600] [ 8] 'm2 hard hm (50)'
[4.4200e+09] [ 600] [ 8] 'm3 hard hm (52)'
[4.4200e+09] [ 600] [ 8] 'm2 soft hm (56)'
[4.4200e+09] [ 600] [ 8] 'm3 soft hm (58)'
[4.4200e+09] [1000] [25] 'm3 hard hex (53)'
[4.4200e+09] [1000] [25] 'm3 soft hex (59)'
其中数字的长度可能会有所不同,行数也会变为......
class(X)
ans =
cell
当我写legend(X)
matlab投诉时。我试图使用类似
sprintf('%d %d %d %s',X{ind,:})
ans =
4420012257 600 8 m2 hard hm (50)
其中ind
递增,但后来我遇到大小可能不同的问题(某些数字更长)
应该绘制的数据有两个基质。所以我期待着最终结果:
plot(t,y); legend(X)
感谢任何帮助!
答案 0 :(得分:2)
假设:
X = {[4.4200e+09] [ 600] [ 8] 'm2 hard hm (50)'
[4.4200e+09] [ 600] [ 8] 'm3 hard hm (52)'
[4.4200e+09] [ 600] [ 8] 'm2 soft hm (56)'
[4.4200e+09] [ 600] [ 8] 'm3 soft hm (58)'
[4.4200e+09] [ 600] [ 8] 'm2 hard hm (50)'
[4.4200e+09] [ 600] [ 8] 'm3 hard hm (52)'
[4.4200e+09] [ 600] [ 8] 'm2 soft hm (56)'
[4.4200e+09] [ 600] [ 8] 'm3 soft hm (58)'
[4.4200e+09] [1000] [25] 'm3 hard hex (53)'
[4.4200e+09] [1000] [25] 'm3 soft hex (59)'}
您可以使用隐式循环,指定每次迭代的输出存储在单元格中,即使用'UniformOutput', false
(等效'un',0
):
X = arrayfun(@(ii) sprintf('%d %d %d %s',X{ii,:}), 1:size(X,1), 'un',0)';
arrayfun相当于:
nrows = size(X,1);
s = cell(nrows,1);
for ii = 1:nrows
s{ii} = sprintf('%d %d %d %s',X{ii,:});
end