Find column position of trues in a binary matrix

2 ビュー (過去 30 日間)
Alex Ferrer
Alex Ferrer 2020 年 3 月 19 日
コメント済み: Alex Ferrer 2020 年 3 月 20 日
Hello,
I have a binary matrix with with a large number of rows (~10^6) and small number of colums (~10) where the number of trues in each row is fixed.
I would like to obtain a matrix that for each row I have the column position of the trues.
For example:
I have the following binary matrix
A = [1 0 1 0 0;...
0 0 1 0 1;
...
...
1 1 0 0 0];
and I would like to obtain
c = [1 3;...
3 5;...
...
...
1 2];

採用された回答

Fangjun Jiang
Fangjun Jiang 2020 年 3 月 19 日
編集済み: Fangjun Jiang 2020 年 3 月 19 日
see if you can get it from [i,j]=find(A)
>> A = [1 0 1 0 0;
0 0 1 0 1;
1 1 0 0 0];
[R,~]=find(A.');
out=transpose(reshape(R,2,[]))
out =
1 3
3 5
1 2
  1 件のコメント
Alex Ferrer
Alex Ferrer 2020 年 3 月 20 日
Thanks, very efficient!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by