喜
我有一个MATLAB程序,我在其中绘制了几个直方图。每次重新缩放hist(轴)。我希望所有的蝾螈都能以相同的比例显示出来
这是该计划:
clc
close all
PopSize=10^3;
SampleSize=1:100:PopSize;
NumberOfSamples=10^2;
Pop=randn(PopSize);
figure(NumberOfSamples+1);
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
答案 0 :(得分:1)
如果您的意思是希望所有hist
次调用都使用相同的计数间隔('bins'或'buckets'),请使用:
hist(Y,x)
x
是bin中心的向量。如果要指定bin边缘而不是中心,也可以使用histc
。
答案 1 :(得分:1)
考虑这段代码修改:
%# ...
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
答案 2 :(得分:0)
您可以使用AXIS命令获取和设置轴限制。例如,在您的第一个绘图之后,您可以执行axvals = axis();
,并在每个后续绘图之后执行axis(axvals);
将所有绘图设置为与第一个绘图相同的限制。