2013-09-16 81 views
0

我有含有细胞如下所示的单元阵列:细胞阵列Matlab的

A= 
<1x4 cell> <1x4 cell> <1x4 cell> 
<1x4 cell> <1x4 cell> <1x4 cell> 
<1x4 cell> <1x4 cell> <1x4 cell> 
<1x4 cell> <1x4 cell> <1x4 cell> 
<1x4 cell> <1x4 cell> <1x4 cell> 
<1x4 cell> <1x4 cell> <1x4 cell> 
<1x4 cell> <1x4 cell> <1x4 cell> 
<1x4 cell> <1x4 cell> <1x4 cell> 
<1x4 cell> <1x4 cell> <1x4 cell> 
<1x4 cell> <1x4 cell> <1x4 cell> 

每个单元包含数值等A{1,1}=[1.6386e+03] [1589] [406.9268] [184.6770]

鉴于a={'el1','el2','el3','el4'},我想获得形式的输出B:

B{1}=[a;A{1,1};A{2,1};A{3,1}...] 
B{1}= 
'el1' 'el2' 'el3' 'el4' 
1638.60000000000 1589   406.926813049605     184.676951989012 
1665.10000000000 1614.60000000000 399.333905068047 362.462074500098 
1709.60000000000 1657.80000000000 389.181059994089 529.870013181953 
... 

B{2}=[a;A{1,2};A{2,2};A{3,2}...] 
... 

这又如何,而无需编写每个单元(即,A {1,1}; A {1,2} ...)进行

回答

0

可以使用串联(cat)和索引,以得到这样的结果:

%Create some inputs 
A = arrayfun(@(~)num2cell(randn(1,4)),zeros(10,3), 'uniformoutput',false); 
a={'el1','el2','el3','el4'}; 

然后创建您的B {1}单元阵列:

%Vertically concatenate the a header with all elements in the first column of A 
B{1} = cat(1, a, A{:,1}) 

创建所有的B

for ixColumn = 1:size(A,2) %Or, loop backwards for slightly better performance. IE "ixColumn = (size(A,2):-1:1" 
    B{ixColumn } = cat(1, a, A{:,ixColumn }); 
end 
+0

感谢这个有用的方法 – user2751649