timetable

Methods

Method Reference: timetable.renamevars

timetable: ttB = renamevars (ttA, vars, newNames)

Rename variables in a timetable.

ttB = renamevars (ttA, vars, newNames) gives each variable in vars the matching name in newNames. Everything else about the variable is kept, its units and its description included.

Dimension names are not renamed here: assign to tt.Properties.DimensionNames for that. A variable cannot be given the row dimension’s name either, the two sharing one namespace.

Renaming a variable of an eventtable that one of its three event properties names carries that designation to the new name. MATLAB clears it instead and does not restore it when the variable is renamed back; see deviation D6.

See also: movevars, timetable

Source Code: timetable

renamevars renames variables and keeps everything else about them.

 t0 = datetime (2024, 1, 1);
 TT = timetable ([12; 45; 23], [34.1; 34.6; 35.0], 'RowTimes', ...
                 t0 + hours (0:2)', 'VariableNames', {'Depth', 'Salinity'});
 TT.Properties.VariableUnits = {'m', 'psu'};
 R = renamevars (TT, 'Salinity', 'Sal');
 R.Properties.VariableNames
ans =
  1x2 cell array

    {'Depth'}    {'Sal'}
 R.Properties.VariableUnits
ans =
  1x2 cell array

    {'m'}    {'psu'}

Dimension names are not renamed here; assign to them instead.

 R.Properties.DimensionNames
ans =
  1x2 cell array

    {'Time'}    {'Variables'}