Select the column with at least one 1 in it
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Rishi Balasubramanian
am 20 Dez. 2020
Kommentiert: Walter Roberson
am 20 Dez. 2020
Hey people
Assume I have a m by n matrix of binary data. How would I be able to identify the column that has the least number of ones?
I used the sum function and compared the max and min. Later on in many loops I realised that it also identifies the column with zero 1s too. How do I avoid that?
The column to be selected must have a minimum of one 1s to n number of ones.
b = sum(H);
bmax = max(b);
bmin = min(b);
RC = find(b==min(b));
%This is what I am using which identifies the column with zero ones. Any simple methods?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 20 Dez. 2020
Bearbeitet: Walter Roberson
am 20 Dez. 2020
find(any(H,1))
If you need at most n ones then:
b = sum(H,1);
find(b >= 1 & b <= n)
4 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices 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!