Percentage of data in given range
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponse acceptée
dpb
le 25 Août 2020
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!