How create an Histogram of datas?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Andrea Miceli
le 10 Juil 2021
Modifié(e) : Paul Hoffrichter
le 10 Juil 2021
Hello to evreyone, I am trying to plot an hist for this string array but I can figure it out. Can someone help me? I need to have an histogram with the name of the groups on the X and the quantity of each one.
[ "3-"
"0"
"0+"
"0-"
"0+"
"0"
"0-"
"0-"
"0-"
"0-"
"3"
"0-"
"U"
"3"
"U"
"U"
"2+"
"0"
"1-"
"2-"
"3-"
"1-"
"2"
"2"
"1-"
"1-"
"1-"
"1-"
"1-"
"1-"
"3"
"3-"
"3"
"3"
"3"
"3"
"3"
"3"
"3"
"3-"
"3"
"U"
"U"
"U"
"3"
"3"
"3"
"3"
"U"
"3"
"3"
"3"
"3"
"3"
"3"
"3"
"3"
"3"
"3"
"3"
"0+"
"3"
"3"
"3"
"2"
"0"
"0"
"0+"
"3-"
"3+"
"0+"
"0+"
"0+"
"2+"
"2+"
"2+"
"0+"
"0+"
"0+"
"0+"
"0+"
"0+"
"0+"
"0+"
"2+"
"0+"
"0+"
"0+"
"0+"
"0"
"0+"
"2+"
"0+"
"0+"
"0+"
"2+"
"0+"
"0+"
"0-"]
0 commentaires
Réponse acceptée
Paul Hoffrichter
le 10 Juil 2021
Modifié(e) : Paul Hoffrichter
le 10 Juil 2021
c = [ "3-"
"0"
"0+"
"0-"
"0+"
"0"
"0-"
"0-"
"0-"
"0-"
"3"
"0-"
"U"
"3"
"U"
"U"
"2+"
"0"
"1-"
"2-"
"3-"
"1-"
"2"
"2"
"1-"
"1-"
"1-"
"1-"
"1-"
"1-"
"3"
"3-"
"3"
"3"
"3"
"3"
"3"
"3"
"3"
"3-"
"3"
"U"
"U"
"U"
"3"
"3"
"3"
"3"
"U"
"3"
"3"
"3"
"3"
"3"
"3"
"3"
"3"
"3"
"3"
"3"
"0+"
"3"
"3"
"3"
"2"
"0"
"0"
"0+"
"3-"
"3+"
"0+"
"0+"
"0+"
"2+"
"2+"
"2+"
"0+"
"0+"
"0+"
"0+"
"0+"
"0+"
"0+"
"0+"
"2+"
"0+"
"0+"
"0+"
"0+"
"0"
"0+"
"2+"
"0+"
"0+"
"0+"
"2+"
"0+"
"0+"
"0-"];
B = categorical(c);
% Method 1: Was unable to get annotations.
figure(11)
histogram(B);
grid on; grid minor;
[N,Categories] =histcounts(B);
for ii = 1:numel(N)
fprintf( "%-3s : %3d \n", Categories{ii}, N(ii) );
end
% Method 2: Using bar, able to get more annotations
Bunq = unique(B);
figure(12), hb = bar( Bunq, N );
xtips1 = hb.XEndPoints;
ytips1 = hb.YEndPoints;
labels1 = string(hb.YData);
text(xtips1,ytips1,labels1,'HorizontalAlignment','center', 'VerticalAlignment','bottom')
grid on; grid minor;
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Histograms dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!