如何在Matlab中更改表列中的名称?
问题描述:
我有两个表,其中一个是具有“sampleID”列的主数据表,其名称如'1 2 3 4 ...'如何在Matlab中更改表列中的名称?
另一个表是结果表,其中列'samples'与名称,如'W1 W2 W3 W4 ...'
我想将结果添加到我的主表中,但首先我相信我必须确保它们的命名方式相同。因此,我正在寻找一种方法来重命名从“W1”到“1”的Results.samples列,如在主表中。
事情是这样的:
Results.samples = Results.samples(-'W')
如果只有这将是容易...
答
%Taking some sample data
sampleID = [38;43;38;40;49];
MasterTable = table(sampleID,'RowNames',{'1','2','3','4','5'});
samples = [71;69;64;67;64];
ResultTable = table(samples,'RowNames',{'W1','W2','W3','W4','W5'});
其中给出了这样的:
T1 =
sampleID
________
1 38
2 43
3 38
4 40
5 49
T2 =
samples
_______
W1 71
W2 69
W3 64
W4 67
W5 64
现在作出调整:
ResultTable.Properties.RowNames = MasterTable.Properties.RowNames ;
Combined =[MasterTable ResultTable] %Required Result
输出:
Combined =
sampleID samples
________ _______
1 38 71
2 43 69
3 38 64
4 40 67
5 49 64
参见:[修改单元,描述和表变量名称(https://www.mathworks.com/help/matlab/matlab_prog/modify-units-descriptions-and-表可变names.html)。列名必须是[有效变量名称](https://www.mathworks.com/help/matlab/matlab_prog/variable-names.html),它不能以数字开头。 – excaza