How to Delete certain rows in a Matrix

1 Ansicht (letzte 30 Tage)
Grant Poggenpohl
Grant Poggenpohl am 6 Feb. 2020
Kommentiert: dpb am 6 Feb. 2020
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?

Akzeptierte Antwort

dpb
dpb am 6 Feb. 2020
Bearbeitet: dpb am 6 Feb. 2020
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 Kommentare
Grant Poggenpohl
Grant Poggenpohl am 6 Feb. 2020
Thank you. very helpful
dpb
dpb am 6 Feb. 2020
No problem. BTW, for large arrays, subset selection will be quite a bit quicker than deletion I suspect altho I didn't try timing...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by