I have a 100 x 2 matrix and would need to filter those rows that has 2 in the first column, and 3 in the second column into a logical.
How should I go about this? Thank you! :)

 採用された回答

Rik
Rik 2019 年 8 月 28 日

0 投票

L=data(:,1)==2 & data(:,2)==3;

6 件のコメント

Guillaume
Guillaume 2019 年 8 月 28 日
編集済み: Guillaume 2019 年 8 月 28 日
Another option:
L = all(data(:, [1, 2]) == [2, 3]) %R2016b or later
Cside
Cside 2019 年 8 月 28 日
i realized the matrix is a struct, == does not seem to work :/
Rik
Rik 2019 年 8 月 28 日
Then you need to extract a matrix from the struct. What is the actual description of your data?
Cside
Cside 2019 年 8 月 28 日
its a 1x 100 struct, with 3 fields (the 2nd and 3rd field to be extracted to a new matrix of 100 X2)
Rik
Rik 2019 年 8 月 28 日
%create some data
s=struct;
for n=1:100
s(1,n).field_a=randi(10,1,1);
s(1,n).field_b=randi(10,1,1);
s(1,n).field_c=randi(10,1,1);
end
data=[s.field_b;s.field_c]';
L=data(:,1)==2 & data(:,2)==3;
Cside
Cside 2019 年 8 月 30 日
Thank you! I got it :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

タグ

質問済み:

2019 年 8 月 28 日

コメント済み:

2019 年 8 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by