timetable.movevars
timetable: ttB = movevars (ttA, vars, 'Before', location)
timetable: ttB = movevars (ttA, vars, 'After', location)
Move variables within a timetable.
ttB = movevars (ttA, vars, …) puts the
variables named in vars before or after location, which
names or numbers another variable. Each variable takes its units,
description and continuity with it.
The row times are not a variable: they can be neither moved nor used as the location, and they stay where they are whatever else is reordered.
See also: addvars, removevars, timetable
Source Code: timetable
movevars reorders variables, each carrying its units and description along with it. The row times stay where they are.
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'};
M = movevars (TT, 'Salinity', 'Before', 'Depth');
M.Properties.VariableNames
ans =
1x2 cell array
{'Salinity'} {'Depth'}
M.Properties.VariableUnits
ans =
1x2 cell array
{'psu'} {'m'}