フィルターのクリア

Logical Indexing into 2d matrix

13 ビュー (過去 30 日間)
luke
luke 2012 年 1 月 2 日
I am trying to use a logical vector to pull out all data from a 2d matrix. The data is below
67 75 52
44 23 34
59 21 30
47 22 22
52 21 46
28 53 43
22 51 11
35 58 31
24 51 20
56 66 22
30 51 30
42 23 24
55 29 68
65 27 74
65 25 52
69 42 88
58 52 31
33 52 24
38 53 39
47 30 40
My logical vector is below
1
0
0
0
0
0
0
0
0
1
0
0
1
1
0
1
1
0
1
1
So what I would like to do is pull all 3 columns of my data and create a new matrix that only has the data items where the logical vector is true (Row 1, Row 10, Row 13...)

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 1 月 2 日
a = [ 67 75 52
44 23 34
59 21 30
47 22 22
52 21 46
28 53 43
22 51 11
35 58 31
24 51 20
56 66 22
30 51 30
42 23 24
55 29 68
65 27 74
65 25 52
69 42 88
58 52 31
33 52 24
38 53 39
47 30 40]
v = logical([ 1
0
0
0
0
0
0
0
0
1
0
0
1
1
0
1
1
0
1
1]);
out = a(v,:)
OR
v = [ 1
0
0
0
0
0
0
0
0
1
0
0
1
1
0
1
1
0
1
1];
out = a(find(v),:)
  1 件のコメント
luke
luke 2012 年 1 月 2 日
works perfectly! Thanks

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by