problem with plotting histogram in matlab

5 visualizzazioni (ultimi 30 giorni)
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 :)

Risposta accettata

Zahra  S. Abd Al-Hassan
Zahra S. Abd Al-Hassan il 19 Nov 2016
Modificato: Zahra S. Abd Al-Hassan il 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 %

Più risposte (2)

Image Analyst
Image Analyst il 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 Commento
Zahra  S. Abd Al-Hassan
Zahra S. Abd Al-Hassan il 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.

Accedi per commentare.


Steven Lord
Steven Lord il 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')

Categorie

Scopri di più su Data Distribution Plots in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by