2012-06-27 75 views
3

我有一个使用Matlab R2010b和boxplot函数的问题。如何更改内置Matlab boxplot函数的百分位数值?

使用以前版本的Matlab,我在boxplot.m文件中做了一些修改,以便可以更改使用的百分位数值。默认情况下,考虑第一和第三四分位数(第二十五和第七十五分位数)来确定盒图来定义胡须。我的兴趣是使用第10和第90百分位。

我尝试了我在互联网上找到的每个解决方案。

所以我的问题是:有没有人找到一种方法来改变默认值(25th和75th)的boxplot函数使用的Matlab(R2010b和之后)百分点?

很多很多谢谢!

+4

每当我修改功能附带MATLAB,我做它的一个拷贝,并用“我的”前缀它。因此,我的修改过的函数在新安装时不会被覆盖。我建议你也这样做,并重新使用修改的2012a版本。 – Jonas

+0

如果您确实想要修改2012b版本,则应修复2106行开始的子函数computeBoxIndices。 – Jonas

+0

谢谢。我不想修改R2012b版本,但是R2010b。我设法修改的那个是R2009a的文件。但我会试着按照乔纳斯的建议重复使用这一个,我会让你注意到的。 – Gnesson

回答

1

您可以通过修改图形对象的属性(而不是修改函数本身)来更改boxplot显示数据/分位数的方式。

这是一段代码,它将修改用于蓝框的分位数(最初,蓝框对应于.25和.75分位数,并将变为.1和.9)。上部/下部晶须的底部会相应地改变。请注意,晶须的尖端没有改变(它们仍然对应于四分位间距的1.5倍)。就像我们改变基本部分一样,你可以改变胡须的提示。

%%% load some data 
load carsmall 
MPG = MPG(ismember(Origin,'USA','rows')); 
Origin = Origin(ismember(Origin,'USA','rows'),:) 
Origin(isnan(MPG),:) = []; 
MPG (isnan(MPG),:) = []; 

%%% quantile calculation 
q = quantile(MPG,[0.1 0.25 0.75 0.9]); 
q10 = q(1); 
q25 = q(2); 
q75 = q(3); 
q90 = q(4); 

%%% boxplot the data 
figure('Color','w'); 

subplot(1,2,1); 
boxplot(MPG,Origin); 
title('original boxplot with quartile', 'FontSize', 14, 'FontWeight', 'b', 'Color', 'r'); 
set(gca, 'FontSize', 14); 

subplot(1,2,2); 
h = boxplot(MPG,Origin) %define the handles of boxplot 
title('modified boxplot with [.1 .9] quantiles', 'FontSize', 14, 'FontWeight', 'b', 'Color', 'r'); 
set(gca, 'FontSize', 14); 

%%% modify the figure properties (set the YData property) 
%h(5,1) correspond the blue box 
%h(1,1) correspond the upper whisker 
%h(2,1) correspond the lower whisker 
set(h(5,1), 'YData', [q10 q90 q90 q10 q10]);% blue box 

upWhisker = get(h(1,1), 'YData'); 
set(h(1,1), 'YData', [q90 upWhisker(2)]) 

dwWhisker = get(h(2,1), 'YData'); 
set(h(2,1), 'YData', [ dwWhisker(1) q10]) 


%%% all of the boxplot properties are here 
for ii = 1:7 
    ii 
    get(h(ii,1)) 
end 

这里是结果。

enter image description here