I need to plot two histograms using the same axis. Code is below:
X1 = GalList.dist;
Y1 = GalList.mass;
XY = [X1,Y1];
XY2=XY(~any(isnan(XY),2),:);
XY2=XY2';
[Y,I]=sort(XY2(1,:));
XY3 = XY2(:,I);
X2 = XY3(1,:);X2=X2';
Y2 = XY(2,:);Y2=Y2';
Y3 = cumsum(Y1);
A = sort(X2);
B = sort(Y2,'descend');
Y4 = cumsum(B);
for s=1:length(X2)
if X2(s)<=20
p(s)=1;
else
p(s)=0;
end
q(s)=p(s).*X2(s);
w(s)=p(s).*Y1(s);
r(s)=p(s).*Y3(s);
end
w(w==0)=[];
w(find(isnan(w)))=[];
q(q==0)=[];
q(find(isnan(q)))=[];
r(r==0)=[];
r(find(isnan(r)))=[];
Q = cumsum(w);
L = 2.6678e+03;
figure(1);
D = cumsum(w/L);
D(D==0)=[];
D(find(isnan(D)))=[];
R = sum(D(:));
hist(D,50)
for s=1:length(X2)
if X2(s)<=20
p(s)=1;
else
p(s)=0;
end
o(s)=p(s).*X2(s);
v(s)=p(s).*Y1(s);
u(s)=p(s).*Y3(s);
o(o==0)=[];
o(find(isnan(o)))=[];
v(v==0)=[];
v(find(isnan(v)))=[];
u(u==0)=[];
u(find(isnan(u)))=[];
Q2 = cumsum(o);
U = 2.6678e+03;
figure(1);
D2 = cumsum(o/U);
D2(D2==0)=[];
D2(find(isnan(D2)))=[];
R2 = sum(D2(:));
hist(D2,50)
I was trying this but it doesn't work:
[n1, xout1] = hist(D,100);
bar(xout1,n1,'r'); grid; hold
[n2, xout2] = hist(D2,100);
bar(xout2,n2,'g');