How create an Histogram of datas?

1 次查看(过去 30 天)
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-"]

采纳的回答

Paul Hoffrichter
Paul Hoffrichter 2021-7-10
编辑:Paul Hoffrichter 2021-7-10
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;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by