Determine percent of array elements which meet condition

27 ビュー (過去 30 日間)
Gabriel Stanley
Gabriel Stanley 2021 年 7 月 20 日
コメント済み: Star Strider 2021 年 7 月 20 日
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?

採用された回答

Star Strider
Star Strider 2021 年 7 月 20 日
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 = 341
T_Pct = 100*T/numel(TF) % Percent 'true' Values
T_Pct = 54.5600
.
  2 件のコメント
Gabriel Stanley
Gabriel Stanley 2021 年 7 月 20 日
Wonderfull, that last operation was what I was completely blanking on. Thanks!
Star Strider
Star Strider 2021 年 7 月 20 日
As always, my pleasure!
.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by