timetable.mergevars
timetable: ttB = mergevars (ttA, vars)
timetable: ttB = mergevars (…, 'NewVariableName', name)
timetable: ttB = mergevars (…, 'MergeAsTable', tf)
Combine several variables of a timetable into one.
ttB = mergevars (ttA, vars) replaces the
variables in vars with a single multi-column one, put where the
first of them was. It is named VarN unless
'NewVariableName' says otherwise, and the merged variables are
no longer reachable by their old names.
Nothing the merged variables carried about themselves survives: one
variable carries one unit, one description, one continuity and one
entry of a custom property describing the variables, and there is no
saying which of them the merged variable should take, so it takes
none: where the continuity is set at all, the merged variable’s
reads 'unset', and a property that was never set stays
unset. The remaining variables keep theirs.
The row times are not a variable and cannot be merged.
Merging a variable of an eventtable that one of its three event
properties names clears that designation, the merged variable being a
different variable under a different name. MATLAB refuses the call
instead, on the ground that the merged variable is no longer a column.
See also: splitvars, timetable
Source Code: timetable
mergevars combines several variables into one multi-column variable, put where the first of them was. Their units do not survive: one variable carries one set, and there is no saying which it should be.
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 = mergevars (TT, {'Depth', 'Salinity'}, 'NewVariableName', 'Cast')
M =
3x1 timetable
Time Cast
____________________ __________
01-Jan-2024 00:00:00 12 34.1
01-Jan-2024 01:00:00 45 34.6
01-Jan-2024 02:00:00 23 35
M.Properties.VariableUnits
ans =
1x1 cell array
{0x0 char}