problem with plotting histogram in matlab

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 :)

 Accepted Answer

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 %

More Answers (2)

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 Comment

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.

Sign in to comment.

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')

Categories

Tags

Community Treasure Hunt

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

Start Hunting!