problem with plotting histogram in matlab

6 vues (au cours des 30 derniers jours)
Zahra  S. Abd Al-Hassan
Zahra S. Abd Al-Hassan le 18 Nov 2016
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 :)

Réponse acceptée

Zahra  S. Abd Al-Hassan
Zahra S. Abd Al-Hassan le 19 Nov 2016
Modifié(e) : Zahra S. Abd Al-Hassan le 19 Nov 2016
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 %

Plus de réponses (2)

Image Analyst
Image Analyst le 18 Nov 2016
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 commentaire
Zahra  S. Abd Al-Hassan
Zahra S. Abd Al-Hassan le 18 Nov 2016
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.

Connectez-vous pour commenter.


Steven Lord
Steven Lord le 18 Nov 2016
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')

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by