Determine percent of array elements which meet condition
27 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gabriel Stanley
am 20 Jul. 2021
Kommentiert: Star Strider
am 20 Jul. 2021
How can I check if a certain percentage of the values in an array meet a condition, e.g. are X% of the values of a given logical array=1?
0 Kommentare
Akzeptierte Antwort
Star Strider
am 20 Jul. 2021
A logical array has two states, true=1 or false=0, so al that is necessary is to find the numbers of 1 values with respect to the total number of elements.
TF = randi([0 1], 25) == 1; % Create Array
T = nnz(TF) % Number Of 'true' Values
T_Pct = 100*T/numel(TF) % Percent 'true' Values
.
2 Kommentare
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!