Get properties of histogram in MATLAB r2012a

1 visualización (últimos 30 días)
Bianca Elena Ivanof
Bianca Elena Ivanof el 12 de Abr. de 2016
Comentada: Bianca Elena Ivanof el 12 de Abr. de 2016
Hey
I am trying to plot a histogram as follows:
x= [1 2 3 4 5];
nbins = 20;
histogram = hist(x,nbins)
However, what I obtain is histogram = count nbins (as if I used the count function) and not a figure; because of this, if I try to get the properties of the figure using get(histogram) I get an error.
I tried only hist(x,nbins), without naming the histogram as above, and that does give me a figure. But then, when I try to get the properties of the figure using get(hist(x,nbins) I get an error.
What I am trying to achieve is to create a histogram, get its properties and then play around with them using 'set'. For that I need to be able to first name the histogram, I assume.
Could anyone please help me?

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 12 de Abr. de 2016
x= [1 2 3 4 5];
nbins = 20;
hist(x,nbins)
set(gcf)
set(gca)

Más respuestas (1)

Guillaume
Guillaume el 12 de Abr. de 2016
Matlab replaced hist with histogram in newer versions of matlab partly because of this silly behaviour.
You have to use hist without any output argument for it to create a figure (or reuse an existing one). It uses the current axes in the current figure. So you could just query these afterward with gca and gcf respectively:
hist(x, nbins); %create histogram in current axes of current figure. If none exist, create them
hfig = gcf; %handle to current figure
hax = gca; %handle to current axes
set(hax, 'XTick', 1:5);
  1 comentario
Bianca Elena Ivanof
Bianca Elena Ivanof el 12 de Abr. de 2016
Yep, thank you! It all makes sense now. I suspected that there was a minor snag with the 2012 version since on the MathWorks blog they use histogram and not hist...

Iniciar sesión para comentar.

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!

Translated by