MATLAB: How to integrate datetime data

datetimeintegrationMATLABplotplotting

I have a plot of datetime data with x axis being datetime (yyyy-MM-dd-HH:mm:ss) and y axis being my data.
my data file looks like this:
2018-03-12-17:50:43 836.00
2018-03-12-17:50:48 871.00
2018-03-12-17:50:54 1116.00
2018-03-12-17:50:59 906.00
2018-03-12-17:51:04 834.00
2018-03-12-17:51:10 927.00
2018-03-12-17:51:15 950.00
2018-03-12-17:51:21 827.00
2018-03-12-17:51:27 999.00
2018-03-12-17:51:33 1088.00
and I convert this data for plotting using this formula
fid = fopen('.\2018-04-02.txt','r');
c = textscan(fid,'%s%f');
fid = fclose(fid);
data = c{2};
%t=datetime(c{1},'Format','HH:mm:ss');
t=datetime(c{1},'Format','yyyy-MM-dd-HH:mm:ss');
figure;
plot(t,data);
Which gives me nice plot of my data depending on time.
I need to convert said data into an incrementing function portraing integration of continous changes adding up depending on time. I tried using the trapz function to conduct numerical integration to no success. The datetime format I'm using does not correlate with trapz function. Also changing the time format into double does not work either.
Basically the plot needs to portray incrementation of my data depending on time.
Any ideas ?
Many thanks in Advance

Best Answer

You can use datenum() on datetime objects to get serial date numbers. Or you could subtract the first datetime entry from them all in order to get duration objects, which you could then use seconds() on to get a numeric version.