필터 지우기
필터 지우기

Histogram wrong Classes help

조회 수: 2 (최근 30일)
Nina Perf
Nina Perf 2022년 2월 4일
편집: Nina Perf 2022년 3월 16일
Hi,
I need help representing data with the histogram function.
figure()
for i = 1:8
subplot(4,2,i), histogram(Data.score)
xlabel('score'), ylabel('Occurrences');
hold on
end
Thank you!

채택된 답변

Voss
Voss 2022년 2월 4일
편집: Voss 2022년 2월 4일
% random integers between 0 and 4; 100 rows by 8 columns
data = randi(5,100,8)-1;
% replace the zeros in columns 1 and 3 with 1's to replicate your situation:
data(data(:,1) == 0,1) = 1;
data(data(:,3) == 0,3) = 1;
% the problem: no bin for 0 when there are no 0's:
figure();
for i = 1:8
subplot(4,2,i);
histogram(data(:,i));
end
% the solution: forcing histogram to include a spot for 0 when there are no
% 0's, by specifying the histogram edges:
figure();
for i = 1:8
subplot(4,2,i);
histogram(data(:,i),(0:5)-0.5);
end
  댓글 수: 2
Nina Perf
Nina Perf 2022년 2월 4일
편집: Nina Perf 2022년 2월 4일
Thank you for your explaination!
It works, however, in the x axis the labels are not centered with the bins. How can I do a graph bar with the x labels?
Voss
Voss 2022년 2월 5일
I edited the answer shortly after posting, to get the bins centered properly. Are you referring to the latest version? They look centered ok to me.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by