For loop to delete rows from matrix
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a number of matrices that are thousands of rows long. I am trying to keep rows that have a certain number in the second column, and delete everything else. I am trying to use a for loop with an embedded if statement but I don't know where to start. Any tips would be nice thank you.
0 commentaires
Réponses (1)
Jan
le 13 Fév 2023
Modifié(e) : Jan
le 14 Fév 2023
M = randi([0, 5], 10000, 5); % Some test data
P = M(M(:, 2) == 3, :); % Keep only rows, which have a 3 in 2nd column
% [EDITED] Typo fixed, ",:" inserted. Thanks, Voss.
2 commentaires
Voss
le 13 Fév 2023
P = M(M(:, 2) == 3, :); % Keep only rows, which have a 3 in 2nd column
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!