Plot multiple time ranges on a single line?
2 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I have a Nx2 timetable of start (column 1) and end (column 2) times, read from a csv file. Each of these time ranges describe a session of data collection for location 'A' An example is this:
A =
'04/19/0022 14:37' '04/19/0022 22:49'
'05/03/0022 14:47' '05/03/0022 23:01'
'05/17/0022 16:58' '05/17/0022 23:02'
'05/31/0022 15:02' '05/31/0022 23:07'
'06/14/0022 14:33' '06/14/0022 23:03'
'10/26/0022 23:28' '10/28/0022 14:14'
'11/02/0022 23:58' '11/04/0022 00:18'
'11/14/0022 17:07' '11/16/0022 01:11'
How might I best plot this data in a time series so each collection session shows as a bar/whisker line on one horizontial axis within the plot?
Additionally, if I had another location and associated variable, 'B', how would I add this second horizontial line with sessions into the graph?
I've drawn an example here (the times don't match to the above data):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1282776/image.jpeg)
I have considered Gantt charts but this seems to be built more specifically towards different mixing of 'A' and 'B' between the horizontial planes.
Thank you.
0 件のコメント
採用された回答
Kyoung Moon Lee
2023 年 2 月 3 日
I have created a code based on the values you wrote down and the picture attached.
You can edit this code by adding the data you need.
%% data
A = {
'04/19/2022 14:37' '04/19/2022 22:49'
'05/03/2022 14:47' '05/03/2022 23:01'
'05/17/2022 16:58' '05/17/2022 23:02'
'05/31/2022 15:02' '05/31/2022 23:07'
'06/14/2022 14:33' '06/14/2022 23:03'
'10/26/2022 23:28' '10/28/2022 14:14'
'11/02/2022 23:58' '11/04/2022 00:18'
'11/14/2022 17:07' '11/16/2022 01:11'};
for ii = 1:height(A)
dnum(ii,1) = datenum(A{ii,1});
dnum(ii,2) = datenum(A{ii,2});
end
%% figure
figure()
for ii = 1:height(A)
% set
hold on;
x = [dnum(ii,1) dnum(ii,2)];
y = [6 6];
% plot
plot(x,y,'k','LineWidth',5)
% deco
xlim([dnum(1,1) dnum(end,2)])
datetick('x','mm-dd','keeplimits','keeplimits')
xlabel('mm-dd (2022)')
ylim([0 10])
yticks([4 6])
yticklabels({'B','A'})
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!