我有一个矩阵(74x74),一个国家/地区的单元格(1,74)和另一个国家/地区的单元格(74,1)。理想情况下这是用矩阵完成的,但是我对单元格和文本有困难,我尝试过horzcat和vertcat函数但没有成功。有任何想法吗?
答案 0 :(得分: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]