How can I extract rows using column values?

조회 수: 2 (최근 30일)
Jacob Ebilane
Jacob Ebilane 2022년 5월 22일
댓글: Jacob Ebilane 2022년 5월 22일
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.

채택된 답변

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

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

MJFcoNaN
MJFcoNaN 2022년 5월 22일
% 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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by