tail

Get bottom rows of table, timetable, or tall array

Description

example

B = tail(A) returns the last eight rows of table or timetable A.

example

B = tail(A,k) returns the last k rows of A.

Examples

collapse all

Create a table that contains 100 rows and five variables.

load patients
T = table(LastName,Gender,Age,Height,Weight);
size(T)
ans = 1×2

   100     5

Preview the last eight rows.

T2 = tail(T)
T2=8×5 table
      LastName         Gender      Age    Height    Weight
    _____________    __________    ___    ______    ______

    {'Foster'   }    {'Female'}    30       70       124  
    {'Gonzales' }    {'Male'  }    48       71       174  
    {'Bryant'   }    {'Female'}    48       66       134  
    {'Alexander'}    {'Male'  }    25       69       171  
    {'Russell'  }    {'Male'  }    44       69       188  
    {'Griffin'  }    {'Male'  }    49       70       186  
    {'Diaz'     }    {'Male'  }    45       68       172  
    {'Hayes'    }    {'Male'  }    48       66       177  

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 = tabularTextDatastore('airlinesmall.csv','TreatAsMissing','NA',...
    'SelectedVariableNames',varnames);
T = tall(ds)
T =

  Mx5 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 =

  Mx5 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 1.6 sec
Evaluation completed in 2 sec
last_rows=8×5 table
    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 = tabularTextDatastore('airlinesmall.csv','TreatAsMissing','NA',...
    'SelectedVariableNames',varnames);
T = tall(ds)
T =

  Mx5 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 =

  Mx5 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.2 sec
b20=20×5 table
    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'}    
      ⋮

Input Arguments

collapse all

Input array, specified as a table or timetable.

Data Types: table | timetable

Number of rows to extract, specified as a positive scalar integer. If A has fewer than k rows, then tail returns all of A.

Output Arguments

collapse all

Requested rows, returned as a table or timetable. The data type of B is the same as A.

Extended Capabilities

Introduced in R2016b