- Used the second argument to the hist() command, to specify the bins to be 1,2,3, etc.
- Got the output from the hist() command (i.e. the frequency count), and used the bar command to plot.
- Set the scale of the y axis to be log rather than linear, using the 'YScale' property of the current axis. (gca is "get current axis")
Changing the axis of a histogram plot in Matlab
8 views (last 30 days)
Show older comments
I want to simulate values that represent a geometric distribution. The plot I have done using the code below seems to produce the right plot. But I want the x axis is badly out of position and also I want the x-axis to be numbered 1,2,3,etc instead of the 10,20,30,etc that I receive now. I also want to plot the Y-axis as a log scale.I am trying to get the plot of 'X' given in the code.
%Geometric Distribution%
N=100;%Number of simulation
P=0.1;
X=zeros(N,1);%simulation data
Ti=0;%Counter
for Ti=2:N
U=rand(1);
a=log10(U);
b=log10(1-P);
c=(a/b);
d=1+round(c);
X(Ti)=d;
Ti=Ti+1;
end
t = 0:N-1;
hist(X);
0 Comments
Answers (1)
the cyclist
on 5 Dec 2011
I am not 100% sure what you mean, but I'll make my best guess.
If in place of you hist() command, you do this:
h = hist(X,1:max(X));
bar(1:max(X),h)
set(gca,'Yscale','log')
then I believe you get what you want. I did three things here:
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!