How create an Histogram of datas?

1 visualización (últimos 30 días)
Andrea Miceli
Andrea Miceli el 10 de Jul. de 2021
Editada: Paul Hoffrichter el 10 de Jul. de 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-"]

Respuesta aceptada

Paul Hoffrichter
Paul Hoffrichter el 10 de Jul. de 2021
Editada: Paul Hoffrichter el 10 de Jul. de 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
0 : 6 0+ : 25 0- : 7 1- : 8 2 : 3 2+ : 7 2- : 1 3 : 29 3+ : 1 3- : 5 U : 7
% 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;

Más respuestas (0)

Categorías

Más información sobre Histograms en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by