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-"]
댓글 수: 0
채택된 답변
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
% 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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Histograms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!