histogram with a specified x-axis limit and bin position
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello Friends,
I have a matrix of a m x n size.
I want to specify the bin size/width, i.e., something like this: bin = [0, 100] Also, I want to specify xlim starting from 0 , and ending at 100 .
I tried something like this: bin = [0;100]; hist(Data, bin)
but it puts 0 as the bin center on x-axis, and does not even show any data plot at around 100, but what I want is to start my histogram plot from 0 (and 0 not to be its center), and to expend it up to 100 . In other words, left tail of histogram should touch 0 without going to -ve x -axis, and the right tail should touch 100 without going above it.
I also tried:
hist(Data [0, 100]);
xlim([0 100]);
but this cuts the plot from middle and shows the plot from 50 above.
I also tried:
hist(Data);
xlim([0 100]);
but it shows almost nothing.
I also tried:
[f,c] = hist(Data);
figure
bar(c,f,10)
axis([0 100 0 100])
but nothing appears in the plot.
I think the problem is happening because I have a data matrix. If I had a single column vector, it would be different, but I want to keep it like this.
0 comentarios
Respuestas (2)
Star Strider
el 3 de Ag. de 2014
If you supply hist with a vector of evenly-spaced bin ranges, it will use those for the centers of the bins.
Example:
X = randi(10, 10, 3);
Ctrs = [0.5:1:9.5];
Xcts = hist(X, Ctrs);
figure(1)
bar(Ctrs, Xcts)
7 comentarios
Star Strider
el 4 de Ag. de 2014
I admit that I am out of ideas. I’ve covered everything I can think of.
If the default values of the bar plots do not do what you want them to do, you can alter their properties by changing the various Barseries Properties. This involves getting into handle graphics, but with a bit of experimentation, you can likely get what you want.
Image Analyst
el 4 de Ag. de 2014
Why don't you just use histc() to get the counts. I can't figure out how many bins you want. One time you say you want a single bin, then another time you say you might go for multiple bars. I have no idea anymore what you want, but with histc() you specify where the bin edges are and you can get exactly what you want - whatever that may be.
0 comentarios
Ver también
Categorías
Más información sobre Data Distribution Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!