我有一个矩阵(74x74),一个国家名称单元格(1,74)和另一个国家名称单元格(74,1)。理想情况下,这是用矩阵完成的,但我在单元格和文本方面遇到了麻烦,我尝试了 horzcat 和 vertcat 函数但没有成功。有任何想法吗?
问问题
241 次
1 回答
4
例子:
%# matrix with row/column headers
M = rand(5,5);
rowHeader = cellstr(num2str((1:5)','Row%d')); %'
colHeader = cellstr(num2str((1:5)','Col%d')); %'
%# create cell array and fill it
C = cell(size(M)+1);
C(2:end,2:end) = num2cell(M);
C(1,2:end) = colHeader;
C(2:end,1) = rowHeader;
结果:
>> C
C =
[] 'Col1' 'Col2' 'Col3' 'Col4' 'Col5'
'Row1' [0.6207] [0.8813] [0.2955] [0.6532] [0.9243]
'Row2' [0.5997] [0.0042] [0.2491] [0.9010] [0.3215]
'Row3' [0.3355] [0.8176] [0.8225] [0.9796] [0.0500]
'Row4' [0.8156] [0.3456] [0.2515] [0.5402] [0.2402]
'Row5' [0.3910] [0.3073] [0.4047] [0.0406] [0.0734]
于 2012-06-29T09:19:33.260 回答