head
First rows of an array or table.
Category: Language Fundamentals > Matrices and Arrays
Syntax
B = head(A)
Returns the first 8 rows.
B = head(A, k)
Returns the first k rows.
Description
head is a quick look at the start of a long data set. It counts rows, so for a row vector (one row) the whole vector is returned; use a column vector or index with v(1:k) to take the first elements.
tail is the counterpart for the last rows.
Input arguments
A- Array, table or timetable.
k- Number of rows to keep.
Output arguments
B- The top rows of
A, with all columns. Fewer rows are returned ifAis shorter.
Example
T = table((1:10)', (10:10:100)', 'VariableNames', {'k', 'v'});
head(T, 3)
head((1:20)', 2)
Output
ans = 3×2 table
k v
_ __
1 10
2 20
3 30
ans = 2×1
1
2