timetable

Methods

Method Reference: timetable.head

timetable: head (tt)
timetable: head (tt, k)
timetable: out = head (tt, k)

Display or return the first k rows of a timetable.

head (tt) displays the first eight rows of tt, or all of them if it has fewer. head (tt, k) displays the first k instead. k must be a real, nonnegative, integer scalar value; a k of zero displays no rows at all rather than raising.

out = head (tt, k) returns those rows in a new timetable instead of displaying them. If k is omitted or empty it defaults to eight.

The rows come back in the order the timetable holds them. head takes the first rows and not the earliest ones, so on a timetable whose times are out of order it returns whatever happens to be stored first. Sort it beforehand to ask the other question.

The time step is read afresh from the row times that are kept, so the head of an hourly timetable is hourly and the head of a timetable whose spacing changes partway may not be.

See also: tail, sortrows, timetable

Source Code: timetable

head shows the first rows of a timetable, eight of them unless told otherwise, which is a quick way to look at a long one.

 t0 = datetime (2024, 1, 1);
 Temp = 15 + (1:12)' / 2;
 TT = timetable (Temp, 'RowTimes', t0 + hours (0:11)');
 head (TT, 4)
            Time            Temp    
    ____________________    ____    

    01-Jan-2024 00:00:00    15.5    
    01-Jan-2024 01:00:00      16    
    01-Jan-2024 02:00:00    16.5    
    01-Jan-2024 03:00:00      17

head takes the first rows and not the earliest ones. On a timetable whose times are out of order it returns whatever happens to be stored first, so sort it beforehand to ask the other question.

 t0 = datetime (2024, 1, 1);
 U = timetable ([30; 10; 40; 20], 'RowTimes', t0 + hours ([2 0 3 1])', ...
                'VariableNames', {'Depth'});
 head (U, 2)
            Time            Depth    
    ____________________    _____    

    01-Jan-2024 02:00:00       30    
    01-Jan-2024 00:00:00       10
 head (sortrows (U), 2)
            Time            Depth    
    ____________________    _____    

    01-Jan-2024 00:00:00       10    
    01-Jan-2024 01:00:00       20

A count of zero is allowed and returns a timetable with no rows, which keeps the variables and their types.

 t0 = datetime (2024, 1, 1);
 TT = timetable ((1:6)', 'RowTimes', t0 + hours (0:5)', ...
                 'VariableNames', {'Reading'});
 E = head (TT, 0);
 size (E)
ans =

   0   1
 E.Properties.VariableNames
ans =
  1x1 cell array

    {'Reading'}