Percentiles without Statistics Toolbox

조회 수: 28 (최근 30일)
ava mazaheri
ava mazaheri 2020년 11월 26일
댓글: MikaelTulldahlCPAC 2021년 3월 5일
Hi,
I have a bunch of histograms from which I need to extract some percentiles (10th, 50th and 90th).
I know about the prctile function, but it requires the Statistics Toolbox in Matlab which I do not have. The only toolbox I have is the Signal Processing Toolbox.
Is there a way of obtaining percentiles other than the prctile function?
//AM

채택된 답변

Star Strider
Star Strider 2020년 11월 26일
Try this:
x = 3*randn(1,100)+5; % Create Data
figure
yyaxis left
h = histogram(x, 20);
hold on
barvals = h.Values;
edgs = h.BinEdges;
ctrs = edgs(1:end-1) + (diff(edgs)/2); % Calculate Bar Center Locations
plot(ctrs, barvals, '+r')
hold off
ylabel('Number')
auc = 100*cumsum(barvals)/sum(barvals)+(0:numel(barvals)-1)*eps*100; % Cumulative Area
prctls = [10, 50, 90]; % Desired Percentiles
prctlctrs = interp1(auc, ctrs, prctls); % Percentile X-Locations
yyaxis right
plot(prctlctrs, prctls, 'dg', 'MarkerFaceColor','g') % Plot Percentiles
hold on
plot(ctrs, auc, '--k') % Plot Area (Optional)
hold off
grid
ylim([0 100])
xlabel('X')
ylabel('Cumulative Percent')
text(prctlctrs, prctls, sprintfc('%2d^{th} Percentile = %5.2f\\rightarrow ', [prctls; prctlctrs].'), 'HorizontalAlignment','right', 'VerticalAlignment','middle')
legend('Histogram', 'Centres', 'Percentiles', 'Area', 'Location','E')
.
  댓글 수: 3
Star Strider
Star Strider 2020년 11월 26일
As always, my pleasure!
MikaelTulldahlCPAC
MikaelTulldahlCPAC 2021년 3월 5일
if anyone needed percentiles unrelated to histograms, it's easy to calculate:
samplePoints = [0.1, 0.5, 0.9];
data = randn(10,3) % 3 sets with 10 samples each
percentiles = interp1(linspace(0, 1, size(data,1)), sort(data), samplePoints);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics and Visualization에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by