table

Methods

Method Reference: table.head

table: head (tbl)
table: head (tbl, k)
table: out = head (tbl, k)

Display or return the first k rows of a table.

head (tbl) displays the first eight rows of the table tbl. If tbl has fewer than eight rows, then all rows are displayed.

head (tbl, k) displays the first k rows of the table tbl. k must be a positive integer scalar value. If tbl has fewer than k rows, then all rows are displayed.

out = head (tbl, k) returns the first k rows in a new table out instead of displaying them. If k is omitted or empty, then it defaults to eight. If tbl has fewer than k rows, then all available rows are returned.

The returned table preserves the variable names, row names, and all other properties of tbl.

Source Code: table

Example: 1

head previews the top of a table without you having to know its size. With no count it returns the first 8 rows (or fewer if the table is short) — handy for glancing at a wide, mixed-type table.

 n = (1:20)';
 T = table (string (num2str (n, 'ID%02d')), datetime (2024, 1, n), ...
            categorical (mod (n, 3), 0:2, {'low', 'mid', 'hi'}), n .^ 2, ...
            'VariableNames', {'Tag', 'Date', 'Band', 'Score'});
 head (T)
     Tag         Date        Band    Score    
    ______    ___________    ____    _____    

    "ID01"    01-Jan-2024     mid        1    
    "ID02"    02-Jan-2024      hi        4    
    "ID03"    03-Jan-2024     low        9    
    "ID04"    04-Jan-2024     mid       16    
    "ID05"    05-Jan-2024      hi       25    
    "ID06"    06-Jan-2024     low       36    
    "ID07"    07-Jan-2024     mid       49    
    "ID08"    08-Jan-2024      hi       64

Pass a count to ask for a specific number of leading rows.

 head (T, 3)
     Tag         Date        Band    Score    
    ______    ___________    ____    _____    

    "ID01"    01-Jan-2024     mid        1    
    "ID02"    02-Jan-2024      hi        4    
    "ID03"    03-Jan-2024     low        9