TB = renamevars(TA, varsNames, newNames)
| Parameter | Description |
|---|---|
| TA | Input table. |
| varsNames | Variable names in input table: character vector, string array or cell array of character vectors. |
| newNames | New names for variables: character vector, string array or cell array of character vectors. |
| Parameter | Description |
|---|---|
| TB | Table object with variable names modified. |
TB = renamevars(TA, varsNames, newNames) renames the variables in the table TA as specified by varsNames and assigns them the new names provided in newNames.
You can also rename all the variables in a table by assigning new names to its VariableNames property using T.Properties.VariableNames = newNames.
In this case, newNames must be a string array or a cell array of character vectors.
C = {'John', 28, true; 'Alice', 35, false; 'Bob', 42, true};
% Convert the cell array to a table
T1 = cell2table(C);
T2 = renamevars(T1, {'C1', 'C2'}, {'Name', 'Age'})
T3 = cell2table(C);
T3.Properties.VariableNames = {'Name', 'Age', 'Married'};
T3
| Version | Description |
|---|---|
| 1.9.0 | initial version |