Logical index multiple columns

3 ビュー (過去 30 日間)
Rainer Danner
Rainer Danner 2019 年 12 月 17 日
編集済み: Ridwan Alam 2019 年 12 月 17 日
We have a 111x1402 array A with one or no logical true for each column.
E.g.:
0 0 1 0 ...
1 0 0 0
0 1 0 1
.
.
.
Now we want to get the values for each of the 1402 columns from another array B which is 111x2.
Meaning the row of the 111 where there is a logical true in array A.
E.g.:
500 142
450 -12
305 125
. .
. .
. .
How can we achieve this in Matlab?
  3 件のコメント
Adam Danz
Adam Danz 2019 年 12 月 17 日
You lost me at , "Now we want to get the values for each of the 1402 columns from another array B which is 111x2." Does array B have 2 or 1402 columns? By "get the values" do you mean the row number of the 1-and-only TRUE in each column?
Rainer Danner
Rainer Danner 2019 年 12 月 17 日
編集済み: Rainer Danner 2019 年 12 月 17 日
B has 111 rows and 2 columns
Get the values = get the values of the 2 columns of B (e.g 500 and 142)
We tried:
cellCenters(bestConn(:, :), :)
Gives the following error:
The logical indices in position 1 contain a true value outside of the array bounds.
cellCenters(bestConn(:, 1), :)
Is working as expected but only returns the values for one and not all...

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

採用された回答

Ridwan Alam
Ridwan Alam 2019 年 12 月 17 日
編集済み: Ridwan Alam 2019 年 12 月 17 日
I believe you are trying to find the row-indices of A, where the row contains a 1, and then extract those rows from B. In that case, this should help:
B(any(A,2),:)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by