timetable

Methods

Method Reference: timetable.addvars

timetable: ttB = addvars (ttA, var1, …, varN)
timetable: ttB = addvars (…, 'Before', location)
timetable: ttB = addvars (…, 'After', location)
timetable: ttB = addvars (…, 'NewVariableNames', newNames)

Add variables to a timetable.

ttB = addvars (ttA, var1, …) appends each array as a new variable at the right-hand end. Every one must have as many rows as the timetable has.

Unnamed variables take the name of the workspace variable they came from, or VarN where there is none. A name that would collide with the row dimension is not allowed and one that arrives by the workspace route is given a suffix instead.

'Before' and 'After' place the new variables beside an existing one, named or numbered. The row times are not a variable and cannot be used as the location, nor can position zero.

The row times are untouched, so the time step is unchanged.

See also: removevars, movevars, timetable

Source Code: timetable

addvars appends variables, naming them after the workspace variables they came from. The row times are untouched, so the time step stands.

 t0 = datetime (2024, 1, 1);
 Depth = [12; 45; 23];
 TT = timetable (Depth, 'RowTimes', t0 + hours (0:2)');
 Salinity = [34.1; 34.6; 35.0];
 addvars (TT, Salinity)
ans =
  3x2 timetable

            Time            Depth    Salinity    
    ____________________    _____    ________    

    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

'Before' and 'After' place the new variable beside an existing one. The row times are not a variable and cannot be used as the location; a name that would clash with the row dimension is refused outright, while one arriving from the workspace is given a suffix instead.

 t0 = datetime (2024, 1, 1);
 TT = timetable ([12; 45; 23], [1; 2; 3], 'RowTimes', t0 + hours (0:2)', ...
                 'VariableNames', {'Depth', 'Cast'});
 addvars (TT, [34.1; 34.6; 35.0], 'Before', 'Cast', ...
          'NewVariableNames', {'Salinity'})
ans =
  3x3 timetable

            Time            Depth    Salinity    Cast    
    ____________________    _____    ________    ____    

    01-Jan-2024 00:00:00       12        34.1       1    
    01-Jan-2024 01:00:00       45        34.6       2    
    01-Jan-2024 02:00:00       23          35       3

A workspace variable called Time becomes Time_1.

 Time = t0 + hours (0:2)';
 addvars (TT, Time).Properties.VariableNames
ans =
  1x3 cell array

    {'Depth'}    {'Cast'}    {'Time_1'}