How can I extract rows using column values?

5 ビュー (過去 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 Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by