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 Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by