matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi I have a 1 x 100 row matrix. I want to calculate in one line what percentage (interms of decimal) are the elements which are the number 1 (matrix is full of 1's, -1's and 0s'.)
Then I would like another one line to give the percentage of -1's.
0 Kommentare
Akzeptierte Antwort
Wayne King
am 14 Jun. 2012
x = randi([-1 1],1,100);
percent1 = 100*(length(x(x==1))/numel(x));
percentminus1 = 100*(length(x(x == -1))/numel(x));
Another way
sum(bsxfun(@eq,x,1))
sum(bsxfun(@eq,x,-1))
0 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Logical 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!