How to Delete certain rows in a Matrix

1 visualización (últimos 30 días)
Grant Poggenpohl
Grant Poggenpohl el 6 de Feb. de 2020
Comentada: dpb el 6 de Feb. de 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?

Respuesta aceptada

dpb
dpb el 6 de Feb. de 2020
Editada: dpb el 6 de Feb. de 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 comentarios
Grant Poggenpohl
Grant Poggenpohl el 6 de Feb. de 2020
Thank you. very helpful
dpb
dpb el 6 de Feb. de 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...

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by