MATLAB: Insert missing date and corresponding values in a matrix

datematrixtimetable

Hi!
I have a matrix: Column 1 (Start time), Column 2 (End time), Column 3 (Values). However, start and end time are not continuos. It is yearly data. How can I plot the values against time? A snapshot of the data:
'03-Jan-2018 16:58:09' '04-Jan-2018 08:08:12' 40.58000000000000
'04-Jan-2018 17:03:22' '05-Jan-2018 08:13:39' 45.22000000000000
'05-Jan-2018 17:06:50' '06-Jan-2018 09:19:06' 34.57000000000000
'06-Jan-2018 11:53:42' '06-Jan-2018 13:37:27' 94.42000000000000
'06-Jan-2018 19:19:20' '07-Jan-2018 13:32:37' 84.92000000000000
Thanks!

Best Answer

If you're looking for timelines that contain segments of start/stop times, here's a method.
data = {
'03-Jan-2018 16:58:09' '04-Jan-2018 08:08:12' 40.58000000000000
'04-Jan-2018 17:03:22' '05-Jan-2018 08:13:39' 45.22000000000000
'05-Jan-2018 17:06:50' '06-Jan-2018 09:19:06' 34.57000000000000
'06-Jan-2018 11:53:42' '06-Jan-2018 13:37:27' 94.42000000000000
'06-Jan-2018 19:19:20' '07-Jan-2018 13:32:37' 84.92000000000000};
startDate = datetime(data(:,1));
stopDate = datetime(data(:,2));
values = [data{:,3}].';
clf()
plot([startDate,stopDate].',[values,values].', 'k-o')
If you'd rather have the line segments connected,
dates = [datetime(data(:,1)), datetime(data(:,2))].';
values = [data{:,3}].';
clf()
plot(dates(:),repelem(values,2,1), 'k-o')