Main Content

tail

Get bottom rows of table, timetable, or tall array

Description

example

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

example

B= tail(A,k)returns the lastkrows ofA.

Examples

collapse all

Create a table that contains 100 rows and five variables.

loadpatientsT = table(LastName,Gender,Age,Height,Weight); size(T)
ans =1×2100 5

Preview the last eight rows.

T2 = tail(T)
T2=8×5 tableLastName 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

创建一个高表和预览下面几行s of data.

Create a tall table for theairlinesmall.csvdata set. Select a subset of the variables to work with. Usetailto extract the last few rows of data.

varnames = {“年”,'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 0.93 sec Evaluation completed in 1.2 sec
last_rows=8×5 tableYear 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 theairlinesmall.csvdata set. Select a subset of the variables to work with, and treat'NA'values as missing data so thatdatastorereplaces them withNaNvalues. Usetailto view the last 20 rows of data.

varnames = {“年”,'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 =尾(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 0.87 sec Evaluation completed in 1.3 sec
b20=20×5 tableYear 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. IfAhas fewer thankrows, thentailreturns all ofA.

Output Arguments

collapse all

Requested rows, returned as a table or timetable. The data type ofBis the same asA.

Extended Capabilities

Introduced in R2016b