How to Delete certain rows in a Matrix

조회 수: 1 (최근 30일)
Grant Poggenpohl
Grant Poggenpohl 2020년 2월 6일
댓글: dpb 2020년 2월 6일
I have a matrix that is 2 columns wide and 18,000 rows long. I wish to save the first 15 rows, then delete 90, save 15 more and remove 90 more rows. and so on until the matrix is completed. I am having trouble with this. should i use loops?

채택된 답변

dpb
dpb 2020년 2월 6일
편집: dpb 2020년 2월 6일
Use indexing expressions...
N1=15; % number to save
N2=90; % number to skip
i1=1:N1+N2:size(x,1); % locations to begin to save
i2=N1:N1+N2:size(x,1); % end locations to save
ix=cell2mat(arrayfun(@colon,i1,i2,'uni',0)); % the addressing vector of those to save
M=M(ix,:); % select the desired rows only
One can do this without the intermediaries but this makes the logic more transparent.
  댓글 수: 2
Grant Poggenpohl
Grant Poggenpohl 2020년 2월 6일
Thank you. very helpful
dpb
dpb 2020년 2월 6일
No problem. BTW, for large arrays, subset selection will be quite a bit quicker than deletion I suspect altho I didn't try timing...

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by