Need help with creating histogram

조회 수: 1 (최근 30일)
Yash Raj Haldaniya
Yash Raj Haldaniya 2022년 3월 1일
댓글: Yash Raj Haldaniya 2022년 3월 1일
hello guys, yesterday i made a code and recived three values s1= -2.401, s2= -2.862, & s3= -3.205. Now i want to plot a histogram for these values with distance where s1 goes from 0.5m to 1m, s2 goes from 1m to 1.5m, and s3 goes from 1.5m to 2m.
I'm very new in matlab and need guidance on how to make histogram for situations like this. please help me. Thank you so much

답변 (2개)

Geoff Hayes
Geoff Hayes 2022년 3월 1일
@Yash Raj Haldaniya - you perhaps want to defined the edges as indicated at bins with bin edges.
  댓글 수: 1
Yash Raj Haldaniya
Yash Raj Haldaniya 2022년 3월 1일
i'm actually very new into this.. can you recommand me any video or explain with some code? thank you

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


Image Analyst
Image Analyst 2022년 3월 1일
Try this:
s1= -2.401;
s2= -2.862;
s3= -3.205;
data = [s1, s2, s3];
% s1 goes from 0.5m to 1m, s2 goes from 1m to 1.5m, and s3 goes from 1.5m to 2m.
edges = [-inf, 0.5, 1.0, 1.5, 2, inf];
histObject = histogram(data, edges);
grid on;
title('Histogram of s', 'FontSize', 20)
xlabel('Value', 'FontSize', 20)
ylabel('Count', 'FontSize', 20)
% Note: all values are negative and thus will all fall into the first bin.
  댓글 수: 3
Image Analyst
Image Analyst 2022년 3월 1일
Then you don't want a histogram/distribution, you want a bar chart of the actual values:
s1= -2.401;
s2= -2.862;
s3= -3.205;
data = [s1, s2, s3];
bar(data);
grid on;
title('Values of s', 'FontSize', 20)
xlabel('Index', 'FontSize', 20)
ylabel('Value', 'FontSize', 20)
Yash Raj Haldaniya
Yash Raj Haldaniya 2022년 3월 1일
yes this is indeed what i wanted it to look like. I'm curious if there is any function to combine these bars and get a line graph?? you getting what i mean?

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

카테고리

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