How to check if there are more ones than zeros in the variable.
Ältere Kommentare anzeigen
For example, if there is the variable x;
x = [1 1 1 1 1 1 1 1 0 0 0];
How to check if it has ones than zeros?
1 Kommentar
Mohammad Sami
am 22 Jul. 2022
if the verctor only contains 1s and 0s, you can just do a sum divided by length of the vector
Akzeptierte Antwort
Weitere Antworten (1)
Image Analyst
am 22 Jul. 2022
Another way (assuming only 1s and 0s in the array):
moreOnes = nnz(x) > numel(x)/2
Kategorien
Mehr zu Operating on Diagonal Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!