Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

what does this code do ?

조회 수: 3 (최근 30일)
ayman daraghmah
ayman daraghmah 2015년 12월 10일
마감: MATLAB Answer Bot 2021년 8월 20일
r1=r1(:,1:length(r1)-1)

답변 (1개)

Adam
Adam 2015년 12월 10일
편집: Adam 2015년 12월 10일
It removes the last element of r1 in a rather over the top manner. Basically the same as:
r1(end) = [];
if r1 is a vector.
Edit:
As pointed out by John D'Errico below and added here to correct the answer, since r1 is a matrix rather than a vector
r(:,end) = [];
is the way to achieve the equivalent and remove the final column as oppose to just the final element as the example above would do for a vector.
See John's comment below for more detail.
  댓글 수: 2
John D'Errico
John D'Errico 2015년 12월 10일
편집: John D'Errico 2015년 12월 10일
Be careful. The indicated code from the OP deletes the last column of a matrix, or if it is a row vector, the final element. I do agree that the operation was done in an over-the-top manner.
r = magic(3)
r =
8 1 6
3 5 7
4 9 2
r(end) = []
r =
8 3 4 1 5 9 6 7
If your goal is to actually remove the last column of a matrix, you would be better off doing it like this:
r = magic(3);
r(:,end) = []
r =
8 1
3 5
4 9
Adam
Adam 2015년 12월 10일
Ah yes, I missed the double indexing.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by