为表头添加后缀 - Matlab



有没有比使用 T.Properties.VariableNames 手动更改后缀"__patients"更快的方法添加到表头中?

法典:

clc;
clear all;
load patients
T = table(Gender,Smoker,Height,Weight);
T.Properties.VariableNames = {'Gender_patients' 'Age_patients' 'Height_patients' 'Weight_patients'}

你可以使用一个循环,它不需要手动:

设置(较短的(表

T = table(1,2,3,4);
T.Properties.VariableNames={'A','B','C','D'}
T =
1×4 table
A    B    C    D
_    _    _    _
1    2    3    4

现在循环:

for k = 1:numel(T.Properties.VariableNames)
T.Properties.VariableNames{k} = sprintf('%s_patients', T.Properties.VariableNames{k});
end

结果


T =
1×4 table
A_patients    B_patients    C_patients    D_patients
__________    __________    __________    __________
1             2             3             4     

最新更新