How can I compute Trapezoidal numerical integration (Q = trapz(X,Y), while my X is a datetime-lalue vector?
14 views (last 30 days)
Show older comments
ADJE JEREMIE ALAGBE
on 27 Jan 2021
Commented: Mathieu NOE
on 27 Jan 2021
Hi everyone, I am trying to calculate the integrale of Y vector ( some observation values) with respect to x-coordinates (datetime values) (see volumes.xlsx file). the column of Y represent volume data, taken at the times contained in X, that take place at 3 minute-intervals, for one day. How can I do that to get a result of integral that is a number, not a time-format value? For example I got sometime this:
Q = trapz(X,Y)
Q =
duration
153:03:00
but I want a result that is number, for example 10.
Any idea to help? Thanks everyone!
0 Comments
Accepted Answer
Mathieu NOE
on 27 Jan 2021
hello
see below , depends if integral must be done on seconds or minutes time stamps - you to choose !
T = readtable('volumes.xlsx') ;
data = cellfun(@double,table2cell(T(:,2)));
% extraction of minutes time vector from date vector
dd = datenum(T{:,1}); % expressed in unit "days"
dd = dd - dd(1); % vector must start at zero
time_minutes = dd*24*60;
time_seconds = time_minutes*60;
% do the trapz integration
Int_vol_minutes = trapz(time_minutes,data)
Int_vol_seconds = trapz(time_seconds,data)
2 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!