Percentage of data in given range

14 ビュー (過去 30 日間)
F Sp
F Sp 2020 年 8 月 25 日
コメント済み: F Sp 2020 年 8 月 25 日
Hello, I'm very sorry to ask since it seems very basic, but I didn't find any useful information on it.
So I have a 1D array. What I want is to give an interval [mean-x,mean+x] and calculate the percentage how many values of all are in this regime. I can easily code this in a few lines, but I was wondering if there is a shorter, more elegant way of calculating it. I checked pdf, paramci (kinda the opposite of what I wanna do) and so on.

採用された回答

dpb
dpb 2020 年 8 月 25 日
Not a defined function, no. There are a couple of related in the Statistics Toolbox for percentiles, etc., but not what you're looking for, precisely.
But, it's simple enough with logical addressing
pct=sum(iswithin(x-mean(x)),-lim,lim)/numel(x)*100;
where iswithin is my utility function
function flg=iswithin(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
flg= (x>=lo) & (x<=hi);
>>
You don't really need the function, of course, it's just "syntactic sugar" to move the compound expression out of the main code...which can come in really handy for more complex cases.
Above does assume a vector in the usage; only a little extra can extend it for arrays.
  1 件のコメント
F Sp
F Sp 2020 年 8 月 25 日
Hey thanks, that's good to know. I thought I was overseeing summit

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by