problem with plotting histogram in matlab

5 次查看(过去 30 天)
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
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
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