How can I return the last value of a vector?

조회 수: 303 (최근 30일)
Thor
Thor 2013년 4월 18일
댓글: Stephen Gerdts 2016년 2월 17일
Dear all,
is there a command in Matlab, which returns the last value of a vector? In R is this command called "tail". For example: X = [1, 2, 3, 4] and I need a command which returns the last value. Like tail(X) = 4. Thank you in advance!

채택된 답변

Kye Taylor
Kye Taylor 2013년 4월 18일
편집: Kye Taylor 2013년 4월 18일
Try
X(end)
In general, if X is a m-by-n-by-p-by...
You can use
X(end,end,end,...)
to access element in last row, last column, last sheet, ...

추가 답변 (1개)

Ehsan R
Ehsan R 2013년 4월 18일
X = [1, 2, 3, 4]
X(end)
ans>>4 ****************************************
X=[1 2 3 4 5 6;7 8 9 10 11 12;13 14 15 16 17 18];
X= 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
A(3,6:end)
ans>>18

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by