how to visualize histogram with Datatime on Axis

조회 수: 13 (최근 30일)
pipor
pipor 2023년 9월 7일
댓글: pipor 2023년 9월 7일
i want to visualize similar but using histogram
Unable to resolve the name 'matlab_data.mat'.

답변 (1개)

Steven Lord
Steven Lord 2023년 9월 7일
You can call histogram with datetime data as the data to be binned. Let's make some random data for the first half of today to use for the example.
sz = [100 1];
dt = datetime('today') + ...
hours(randi([0 11], sz)) + ...
minutes(randi([0 60]));
Specify the bin edges as each hour from midnight to noon.
edges = datetime('today') + hours(0:12);
Create the histogram and set the x axis ticks to be every other hour from the edges vector. Specifying every hour IMO made the axes a bit too "busy".
histogram(dt, edges)
xticks(edges(1:2:end))
  댓글 수: 3
Steven Lord
Steven Lord 2023년 9월 7일
Okay, so you don't actually want to call histogram but you want a plot that looks like a histogram? In that case I'd look through the Plot Gallery (or the Plots tab on the Toolstrip in your MATLAB installation) to find a plot that looks like what you're trying to create.
In the Plot Gallery you can Open Example to open an example file that shows how to create plots of that type then copy and adapt the code in those examples to suit your data and needs.
In the Plots tab in the Toolstrip, look for the name of the function underneath the thumbnail picture and open the documentation for that function. Alternately if you've selected the data you want to visualize in the Workspace window you can directly click on the thumbnail and MATLAB will create that type of plot using your data.
I suspect the bar function will do what you want, and it too supports specifying datetime data as x data.
x = datetime('today') + days(0:9);
y = (1:10).^2;
bar(x, y)
pipor
pipor 2023년 9월 7일
ok thanks..

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by