开发者

fix scale of multiple hist in MATLAB

hi

I have a MATLAB program in which I draw several histograms. each time the hist is re-scaled (the axes). I want all of the hists to be shown at the same scale.

this is the program:

clc  
close all  
PopSize=10^3;  
SampleSize=1:100:PopSize;  
NumberOfSamples=10^2;  
Pop=randn(PopSize);  
figure(NumberOfSamples+1开发者_C百科);  
hist(Pop);  
sample=[];
for j=1:100:PopSize  
for i=1:1:NumberOfSamples  
    Pop=SHUFFLE(Pop);  
    sample(i)=mean(Pop(1:j));  
end  
figure(i+j);  
hist(sample);  
end


If you mean that you want all hist calls to use the same counting intervals ('bins' or 'buckets'), use:

hist(Y,x)

Where x is a vector of bin centers. You can also use histc if you want to specify bin edges instead of centers.


Consider this code modification:

%# ...
h = [];
for j=1:100:PopSize
    %# ...
    h(end+1) = gca;                        %# get handle to histogram axis
end

mx = max( cellfun(@max,get(h,'YLim')) );   %# get the max count of all histograms
set(h, 'YLim',[0 mx])                      %# set the y-limit of all axes


You can use the AXIS command to both get and set the axis limits. For instance, after your first plot you could do axvals = axis();, and after each subsequent plot do axis(axvals); to set all the plots to the same limits as the first one.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜