How can I compute Trapezoidal numerical integration (Q = trapz(X,Y), while my X is a datetime-lalue vector?

11 次查看(过去 30 天)
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!

采纳的回答

Mathieu NOE
Mathieu NOE 2021-1-27
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by