Find column position of trues in a binary matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Alex Ferrer
am 19 Mär. 2020
Kommentiert: Alex Ferrer
am 20 Mär. 2020
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];
0 Kommentare
Akzeptierte Antwort
Fangjun Jiang
am 19 Mär. 2020
Bearbeitet: Fangjun Jiang
am 19 Mär. 2020
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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!