필터 지우기
필터 지우기

Get properties of histogram in MATLAB r2012a

조회 수: 1 (최근 30일)
Bianca Elena Ivanof
Bianca Elena Ivanof 2016년 4월 12일
댓글: Bianca Elena Ivanof 2016년 4월 12일
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?

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 12일
x= [1 2 3 4 5];
nbins = 20;
hist(x,nbins)
set(gcf)
set(gca)

추가 답변 (1개)

Guillaume
Guillaume 2016년 4월 12일
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
Bianca Elena Ivanof
Bianca Elena Ivanof 2016년 4월 12일
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...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by