Histogram distribution with two vectors
9 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Histograms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!