Main Content

tail

Get bottom rows of array or table

Description

example

tail(A) displays the last eight rows of array, table, or timetable A in the Command Window without storing a value.

example

tail(A,k) displays the last k rows of A.

example

B = tail(___) returns the requested rows of A for either of the previous syntaxes. The data type of B is the same as the data type of A.

Examples

collapse all

Create a matrix with 100 rows, and display the last eight rows of the matrix.

If you do not specify an output argument, tail does not return a value. It only displays the bottom of the matrix.

A = repmat((1:100)',1,4);
tail(A)
    93    93    93    93
    94    94    94    94
    95    95    95    95
    96    96    96    96
    97    97    97    97
    98    98    98    98
    99    99    99    99
   100   100   100   100

Create a table from a file with 1468 rows.

T = readtable("outages.csv","TextType","string");
size(T)
ans = 1×2

        1468           6

Display the last three rows. If you do not specify an output argument, tail does not return a value. It only displays the bottom of the table.

tail(T,3)
      Region            OutageTime          Loss     Customers       RestorationTime             Cause      
    ___________    ____________________    ______    __________    ____________________    _________________

    "MidWest"      02-Jan-2011 14:41:00    364.24    2.8432e+05    04-Jan-2011 04:43:00    "winter storm"   
    "SouthEast"    20-Dec-2013 19:52:00    2.3096        1038.2    20-Dec-2013 23:29:00    "thunder storm"  
    "SouthEast"    14-Sep-2011 11:55:00    45.042         11835    14-Sep-2011 13:28:00    "equipment fault"

Create a table by reading data from a spreadsheet. Display the size of the table, showing that it has 1468 rows.

T = readtable("outages.csv","TextType","string");
size(T)
ans = 1×2

        1468           6

Return another table that has the last eight rows of T.

T2 = tail(T)
T2=8×6 table
      Region            OutageTime          Loss     Customers       RestorationTime             Cause       
    ___________    ____________________    ______    __________    ____________________    __________________

    "West"         04-Dec-2010 12:09:00    245.72     1.074e+05    07-Dec-2010 13:05:00    "winter storm"    
    "West"         05-Jan-2013 05:52:00         0             0    05-Jan-2013 06:08:00    "attack"          
    "West"         01-Dec-2010 04:12:00    369.43           NaN    01-Dec-2010 04:28:00    "energy emergency"
    "West"         21-Nov-2011 16:51:00         0             0    21-Nov-2011 16:55:00    "attack"          
    "SouthEast"    03-Jan-2011 05:52:00       NaN    2.7596e+05    06-Jan-2011 05:25:00    "winter storm"    
    "MidWest"      02-Jan-2011 14:41:00    364.24    2.8432e+05    04-Jan-2011 04:43:00    "winter storm"    
    "SouthEast"    20-Dec-2013 19:52:00    2.3096        1038.2    20-Dec-2013 23:29:00    "thunder storm"   
    "SouthEast"    14-Sep-2011 11:55:00    45.042         11835    14-Sep-2011 13:28:00    "equipment fault" 

Input Arguments

collapse all

Input data, specified as an array, cell array, table, or timetable.

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

Extended Capabilities

Version History

Introduced in R2016b

expand all