problem with plotting histogram in matlab

조회 수: 5 (최근 30일)
Zahra  S. Abd Al-Hassan
Zahra S. Abd Al-Hassan 2016년 11월 18일
편집: Zahra S. Abd Al-Hassan 2016년 11월 19일
Hey
I want to have some strings ind the x-axis and procent % in the y-axis. How can I make a histogram in matlab with af string i x-axis and procent in y-axis?
thank you :)

채택된 답변

Zahra  S. Abd Al-Hassan
Zahra S. Abd Al-Hassan 2016년 11월 19일
편집: Zahra S. Abd Al-Hassan 2016년 11월 19일
I dont think you really understand what I want :(
I want a graph and the x-axis should be named:
'A' 'B' 'C' 'D' 'E'
The y-axis should go from 0-100 %.
A will show 13.5%
B will show 21.4%
C will show 8.5 %
D will show 10.8 %
E will show 30.9 %

추가 답변 (2개)

Image Analyst
Image Analyst 2016년 11월 18일
Try this:
data = randn(1,1000000);
histogram(data, 'normalization', 'probability', 'edgecolor', 'none'); % or might want 'normalization', 'probability'
grid on;
ax = gca
ax.XTickLabels = {'image', 'analyst', 'rocks', 'whatever', 'fubar', 'snafu', 'blah blah', };
fontSize = 20;
title('Never say "blah blah blah" when "blah" will do', 'fontSize', fontSize);
xlabel('My Categories', 'fontSize', fontSize);
ylabel('Percent', 'fontSize', fontSize);
  댓글 수: 1
Zahra  S. Abd Al-Hassan
Zahra S. Abd Al-Hassan 2016년 11월 18일
What should I enter if I want to have 0-100% on the y axis? And how can I for each string on the x axis even go in and enter the relevant value.
For example, if I want to enter 50% for 'analyst' 20% for 'rock' etc.

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


Steven Lord
Steven Lord 2016년 11월 18일
If you have categorical data, for instance a list of weather reports:
weatherValues = {'sunny', 'cloudy', 'rain', 'thunderstorm'};
indices = randi(length(weatherValues), 1, 100);
weatherPerDay = weatherValues(indices);
weatherCategories = categorical(weatherPerDay); % or
weatherCategories = categorical(indices, 1:length(weatherValues), weatherValues);
and you're using release R2015b or later you can create a categorical histogram.
histogram(weatherCategories, 'Normalization', 'probability')
To check, how many elements in weatherCategories were 'rain'? Since we had 100 samples, this should be 100 times the percentage given in the histogram for the 'rain' bar.
sum(weatherCategories == 'rain')

카테고리

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