Histogram distribution with two vectors

조회 수: 11 (최근 30일)
Naser Khan
Naser Khan 2022년 7월 4일
편집: Torsten 2022년 7월 5일
Hi there,
I have two separate vectors, one for vehicle power and another one for vehicle speed. I am trying to have a histogram to show a power vs speed distribution. I have attached an image to assist with understanding.
Thanks,
  댓글 수: 3
Naser Khan
Naser Khan 2022년 7월 4일
Hi,
I have two vectors for the two axes. I am essentially looking to have the frequency (y-axis) of the power at different speed (x-axis). The speeds can be spaced out in steps of 5 or 10.
My query is whether its possible to plot a histogram based on an X-Y plot?
Thanks
Torsten
Torsten 2022년 7월 5일
편집: Torsten 2022년 7월 5일
And what is the solid line in the graph ? Is it a kind of regression line approximating the speed/frequency relationship ?

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

답변 (1개)

Image Analyst
Image Analyst 2022년 7월 4일
Since you say "I have two vectors for the two axes. I am essentially looking to have the frequency (y-axis) of the power at different speed (x-axis). The speeds can be spaced out in steps of 5 or 10."
then your y vector is already the frequency (histogram) so no need to call histogram() because you've already done that. The histogram function can do the plotting for you, or if you'd rather plot the frequency as bars like your graphic showed, then you can use bar
bar(speedVector, frequencyVector);
grid on;
  댓글 수: 2
Naser Khan
Naser Khan 2022년 7월 4일
I see, is there a way I can group my speed vector into segments so the x axis doesn’t become very long?
I believe this may require me to do normalising with a histogram?
Thanks
Image Analyst
Image Analyst 2022년 7월 4일
Sure, when you got your y values (counts in each hisotgram bin), you could specify the bin edges if you wish.
% Specify which x values should be grouped into each bin
% by definining the edges (dividing lines) between bins.
edges = [-inf, 0:20:100, inf];
% Get the y values which is the frequency (count)
% of how many data points are in each bin.
[counts, edges] = histcounts(data, edges);
bar(edges(1:end-1), counts);
grid on;

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

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by