delete certain elements in a matrix
Ältere Kommentare anzeigen
Is there any way to delete certain rows(with a pattern) in a matrix
like to delete rows 1,6,11,21,26,..... using a loop
Thanks.
Akzeptierte Antwort
Weitere Antworten (2)
In a loop? Not really.
All at once? Absolutely.
DATA = rand(50,5);
rowsToDelete = [1,6,11,21,26];
DATA(rowsToDelete,:) = [];
If you mean that your rows to delete has the pattern of rows 1,6,11,16, etc, then just do this:
numRows = size(DATA,1);
rowsToDelete = [1:10:numRows 6:10:numRows];
DATA(rowsToDelete,:) = [];
3 Kommentare
dav
am 14 Mär. 2013
Jan
am 14 Mär. 2013
This is much faster than a loop for large arrays. Shrinking arrays in a loop has the same drawback as letting them grow: In each iteration the new array must be allocated and the contents of the old one is copied. This is very expensive.
dav
am 14 Mär. 2013
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!