tail
Get bottom rows of array or table
Description
tail( displays the last eight rows
of array, table, or timetable A)A in the Command Window without
storing a value.
returns
the requested rows of B = tail(___)A for either of the previous syntaxes.
The data type of B is the same as the data type of
A.
Examples
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" 2011-01-02 14:41 364.24 2.8432e+05 2011-01-04 04:43 "winter storm"
"SouthEast" 2013-12-20 19:52 2.3096 1038.2 2013-12-20 23:29 "thunder storm"
"SouthEast" 2011-09-14 11:55 45.042 11835 2011-09-14 13:28 "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" 2010-12-04 12:09 245.72 1.074e+05 2010-12-07 13:05 "winter storm"
"West" 2013-01-05 05:52 0 0 2013-01-05 06:08 "attack"
"West" 2010-12-01 04:12 369.43 NaN 2010-12-01 04:28 "energy emergency"
"West" 2011-11-21 16:51 0 0 2011-11-21 16:55 "attack"
"SouthEast" 2011-01-03 05:52 NaN 2.7596e+05 2011-01-06 05:25 "winter storm"
"MidWest" 2011-01-02 14:41 364.24 2.8432e+05 2011-01-04 04:43 "winter storm"
"SouthEast" 2013-12-20 19:52 2.3096 1038.2 2013-12-20 23:29 "thunder storm"
"SouthEast" 2011-09-14 11:55 45.042 11835 2011-09-14 13:28 "equipment fault"
Input Arguments
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
The
tail 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.
The tail function
fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced in R2016bDisplay or return the bottom rows of a vector, matrix, multidimensional array, or
cell array using tail. In previous releases,
tail supports only tables, timetables, and tall
arrays.
When you call tail without a specified output argument,
tail displays the selected rows of the table but does not
store the output in the ans variable. In previous releases,
calling tail without a specified output argument causes the
output to be stored in ans.
Calling tail in a live script is usually not recommended.
Instead, display the table or timetable by typing the variable name with no semicolon. The
Live Editor provides a widget that enables you to examine the entire table or timetable.
However, if you do call tail in a live script, it is recommended
that you assign the output to a variable so that the live script creates a widget for the
output.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- 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)