Effacer les filtres
Effacer les filtres

How can I extract rows using column values?

4 vues (au cours des 30 derniers jours)
Jacob Ebilane
Jacob Ebilane le 22 Mai 2022
Commenté : Jacob Ebilane le 22 Mai 2022
I'm trying to use the emnist byclass data set which includes digits and upper/lower case letters. I don't need all of the letters so I wanted to remove the unnecessary ones. The emnist set uses the first column as a label 0-61 and only need for example 0-9 and <49, 55, 11, 32, 13, 29, 30, 20, 33, 43, 24> these ones.

Réponse acceptée

Walter Roberson
Walter Roberson le 22 Mai 2022
classes_needed = [49, 55, 11, 32, 13, 29, 30, 20, 33, 43, 24];
mask = ismember(emnist(:,1), classes_needed);
subset = emnist(mask,:);
  1 commentaire
Jacob Ebilane
Jacob Ebilane le 22 Mai 2022
Worked like a charm, thank you kind sir.

Connectez-vous pour commenter.

Plus de réponses (1)

MJFcoNaN
MJFcoNaN le 22 Mai 2022
% random matrix
A=randi(50,10)
A = 10×10
17 33 20 13 5 20 1 20 34 20 26 13 43 3 14 46 22 22 24 41 29 49 17 9 50 41 48 20 17 35 11 26 20 15 4 30 50 18 35 32 22 12 1 12 40 27 25 35 4 21 12 17 44 47 7 26 46 4 50 47 21 41 40 38 6 31 4 4 26 14 23 22 42 18 20 1 23 3 8 41 28 27 29 28 4 32 5 31 49 29 6 3 27 14 26 45 15 39 14 32
% needed lines index
ind=ismember(A(:,1), [0:9, 49, 55, 11, 32, 13, 29, 30, 20, 33, 43, 24]);
% needed rows
B=A(ind, :)
B = 3×10
29 49 17 9 50 41 48 20 17 35 11 26 20 15 4 30 50 18 35 32 6 3 27 14 26 45 15 39 14 32

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by