Plotting histogram question ?

How do I plot the histogram of a set of data values in terms of percentage of cumulative frequency? Something like, I want the range to be from 0 to 100%, not from 0 to total number of data.
I am not sure if I made myself understood. Please do ask for details if you need any.

 채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 8월 13일

1 개 추천

a=rand(100,1);
a(a>=0.7)=1;
a(a<=0.2)=2;
a(a<0.7 & a>0.2)=3;
figure(1);n=hist(a(:),0:5);
percent=n/sum(n);
figure(2);bar(0:5,percent);

댓글 수: 6

Jason
Jason 2011년 8월 13일
Hi, is it possible to list down the actual percentage value for data in each container?
Jason
Jason 2011년 8월 13일
I actually have to plot this for all the values within a 4-D cell array. There are 59,500 values in total, I need to know the cumulative frequency of those values. Maybe I need to use 'cumsum'?
Fangjun Jiang
Fangjun Jiang 2011년 8월 13일
a=rand(2,3,4,5);
figure(1);hist(a(:),0:0.1:1);
n=hist(a(:),0:0.1:1);
figure(2);bar(0:0.1:1,n/sum(n));
Jason
Jason 2011년 8월 13일
What am I thinking, the answer is clearly in the code you wrote. Sorry, my mind is so cluttered right now. Thanks for the help though, very much appreciated.
Walter Roberson
Walter Roberson 2011년 8월 13일
Warning: the logic used above will fail if there are no values to be histogrammed. sum(n) would be 0 and you would get 0/0 . Be safe, program defensively!
Jason
Jason 2011년 8월 13일
Thanks, Walter.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Histograms에 대해 자세히 알아보기

태그

질문:

2011년 8월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by