필터 지우기
필터 지우기

Keeping rows of a matrix between two indicies.

조회 수: 2 (최근 30일)
Jason
Jason 2018년 2월 1일
댓글: Jason 2018년 2월 1일
Hi. I want to remove all rows from a matrix below idx1 and above idx2. that is I only want to keep rows that are between idx1 and idx2.
I have used this to do the 1st part:
C2(1:idx1,:) = []; %Trim the first rows upto idx1
But can't quite work out how to include removing above idx2 as the indexes will have changed now the above removal has occurred?
Thanks

채택된 답변

Birdman
Birdman 2018년 2월 1일
편집: Birdman 2018년 2월 1일
One approach:
A=randi([1 5],15,5);%demo data
idx2=3;idx1=8;
A=A(idx2:idx1,:)
  댓글 수: 3
Birdman
Birdman 2018년 2월 1일
I changed it. Now check the answer.
Jason
Jason 2018년 2월 1일
Perfect, thanks Jason

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jos (10584)
Jos (10584) 2018년 2월 1일
I just want to point you to the following logic: if you start removing at the end, no indices will change:
A(ix2:end,:) = []
A(1:ix1,:) = []
However, you are much better off using Birdman's approach:
A = A(ix1+1:ix2-1,:) % include ix1 and ix2 for removal, per your example

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by