How can I extract rows using column values?

3 views (last 30 days)
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.

Accepted Answer

Walter Roberson
Walter Roberson on 22 May 2022
classes_needed = [49, 55, 11, 32, 13, 29, 30, 20, 33, 43, 24];
mask = ismember(emnist(:,1), classes_needed);
subset = emnist(mask,:);

More Answers (1)

MJFcoNaN
MJFcoNaN on 22 May 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

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!