在表标题中添加后缀-Matlab

时间:2019-12-13 20:24:58

标签: 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'}

1 个答案:

答案 0 :(得分:2)

您可以使用循环,该循环要少一些手动操作:

设置(较短的)表格

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