tail

Get bottom rows of tall array

Syntax

Description

example

Y = tail(X) returns the last eight rows of tall array X.

example

Y = tail(X,k) returns the last k rows of tall array X.

Examples

collapse all

Create a tall table and preview the bottom few rows of data.

Create a tall table for the airlinesmall.csv data set. Select a subset of the variables to work with. Use tail to extract the last few rows of data.

varnames = {'Year','Month','ArrDelay','DepDelay','UniqueCarrier'};
ds = datastore('airlinesmall.csv','TreatAsMissing','NA',...
    'SelectedVariableNames',varnames);
T = tall(ds)
T =

  M×5 tall table 

    Year    Month    ArrDelay    DepDelay    UniqueCarrier
    ____    _____    ________    ________    _____________

    1987    10        8          12          'PS'         
    1987    10        8           1          'PS'         
    1987    10       21          20          'PS'         
    1987    10       13          12          'PS'         
    1987    10        4          -1          'PS'         
    1987    10       59          63          'PS'         
    1987    10        3          -2          'PS'         
    1987    10       11          -1          'PS'         
    :       :        :           :           :
    :       :        :           :           :

tt = tail(T)
tt =

  M×5 tall table 

    Year    Month    ArrDelay    DepDelay    UniqueCarrier
    ____    _____    ________    ________    _____________

    ?       ?        ?           ?           ?            
    ?       ?        ?           ?           ?            
    ?       ?        ?           ?           ?            
    :       :        :           :           :
    :       :        :           :           :

Collect the results into memory to view the data.

last_rows = gather(tt)
Evaluating tall expression using the Local MATLAB Session:
- Pass 1 of 1: Completed in 0 sec
Evaluation completed in 1 sec

last_rows = 

    Year    Month    ArrDelay    DepDelay    UniqueCarrier
    ____    _____    ________    ________    _____________

    2008    12        14          1          'DL'         
    2008    12        -8         -1          'DL'         
    2008    12         1          9          'DL'         
    2008    12        -8         -4          'DL'         
    2008    12        15         -2          'DL'         
    2008    12       -15         -1          'DL'         
    2008    12       -12          1          'DL'         
    2008    12        -1         11          'DL'         

Preview the last 20 rows of data in a tall table.

Create a tall table for the airlinesmall.csv data set. Select a subset of the variables to work with, and treat 'NA' values as missing data so that datastore replaces them with NaN values. Use tail to view the last 20 rows of data.

varnames = {'Year','Month','ArrDelay','DepDelay','UniqueCarrier'};
ds = datastore('airlinesmall.csv','TreatAsMissing','NA',...
    'SelectedVariableNames',varnames);
T = tall(ds)
T =

  M×5 tall table 

    Year    Month    ArrDelay    DepDelay    UniqueCarrier
    ____    _____    ________    ________    _____________

    1987    10        8          12          'PS'         
    1987    10        8           1          'PS'         
    1987    10       21          20          'PS'         
    1987    10       13          12          'PS'         
    1987    10        4          -1          'PS'         
    1987    10       59          63          'PS'         
    1987    10        3          -2          'PS'         
    1987    10       11          -1          'PS'         
    :       :        :           :           :
    :       :        :           :           :

tt = tail(T,20)
tt =

  M×5 tall table 

    Year    Month    ArrDelay    DepDelay    UniqueCarrier
    ____    _____    ________    ________    _____________

    ?       ?        ?           ?           ?            
    ?       ?        ?           ?           ?            
    ?       ?        ?           ?           ?            
    :       :        :           :           :
    :       :        :           :           :

Collect the results into memory to view the data.

b20 = gather(tt)
Evaluating tall expression using the Local MATLAB Session:
- Pass 1 of 1: Completed in 1 sec
Evaluation completed in 1 sec

b20 = 

    Year    Month    ArrDelay    DepDelay    UniqueCarrier
    ____    _____    ________    ________    _____________

    2008    12         0         -4          'CO'         
    2008    12       -16         13          'CO'         
    2008    12        17         -3          'CO'         
    2008    12         3         -5          'CO'         
    2008    12         2          6          'DL'         
    2008    12         6         -2          'DL'         
    2008    12        37         35          'DL'         
    2008    12        -1         -6          'DL'         
    2008    12        39         12          'DL'         
    2008    12        -3         -6          'DL'         
    2008    12        -6         -1          'DL'         
    2008    12        -2          1          'DL'         
    2008    12        14          1          'DL'         
    2008    12        -8         -1          'DL'         
    2008    12         1          9          'DL'         
    2008    12        -8         -4          'DL'         
    2008    12        15         -2          'DL'         
    2008    12       -15         -1          'DL'         
    2008    12       -12          1          'DL'         
    2008    12        -1         11          'DL'         

Input Arguments

collapse all

Input array, specified as a tall array.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | table | cell | categorical | datetime | duration | calendarDuration

Number of rows to extract, specified as a positive scalar integer. If the tall array has fewer than k rows, then tail returns the entire array.

Output Arguments

collapse all

Requested rows, returned as an unevaluated tall array. To calculate Y and bring it into memory, use gather(Y). For more information, see Deferred Evaluation of Tall Arrays.

More About

collapse all

Tips

  • If you are unsure whether the result returned by gather(X) will fit in memory, then use gather(head(X)) or gather(tail(X)). These commands still fully evaluate the tall array X, but only a small subset of the result is returned in memory.

See Also

| | |

Introduced in R2016b

Was this topic helpful?