tail
Get bottom rows of table, timetable, or tall array
Syntax
Description
Examples
Preview Table
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
Preview Contents of Tall Table
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.1 sec Evaluation completed in 1.4 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'}
Retrieve Specified Number of Rows in Tall Array
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 0.43 sec Evaluation completed in 0.56 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
A
— Input array
table | timetable
Input array, specified as a table or timetable.
Data Types: table
| timetable
k
— Number of rows to extract
scalar
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
B
— Requested rows
table | timetable
Requested rows, returned as a table or timetable. The data type
of B
is the same as A
.
Extended Capabilities
Tall Arrays
Calculate with arrays that have more rows than fit in memory.
This function fully supports tall arrays. For more information, see Tall Arrays.
You can use head
and tail
with
tall arrays of any valid underlying data type (single
, double
, int8
, datetime
, table
,
and so on).
If you are unsure whether the result returned by gather(A)
will
fit in memory, then use gather(head(A))
or gather(tail(A))
.
These commands still fully evaluate the tall array A
,
but only return a small subset of the result in memory.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Distributed Arrays
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Abrir ejemplo
Tiene una versión modificada de este ejemplo. ¿Desea abrir este ejemplo con sus modificaciones?
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)