MATLAB: Area in (mm) between the two graphs (integrale)

areagraphintegralintegrationnumerical integration

Hello, I'm new at matlab so I'm a bit lost. But need this for my master thesis.
I'm working on green roofs, and in order to find out how much of the rain the roof can store, I need to finde the area (mm) – the integrale – as the difference between the two graphs. This is the area going from the starttime to the endtime, marked with orange on the picture. And I get the data in mm/min, (Q=mm/min). I was trying to do it like this:
%% Start and end time for the area starttime=datenum('21-09-2014 03:52:50','dd-mm-yyyy HH:MM'); endtime=datenum('21-09-2014 04:40:44','dd-mm-yyyy HH:MM');
%% Load DMI rain gauge data gaugeDataFolder='SVKdata';
[svkEventSummary,svkIntSummary,svkIntTs]=LoadSvk(gaugeDataFolder);
svkIntTs(1,:)=[]; % Deleting the first row
svkIntTs(:,1)=svkIntTs(:,1)+2/24; % correction for the timezone
% 'Cutting' the svkdata out between 'starttime' and 'endtime': tmp=svkIntTs(:,1); idx=(tmp>starttime & tmp<endtime); cutSerie=svkIntTs(idx,1:2);
%% Function fun=@(t)cutSerie*t;
%% Integral
q = integral(fun,starttime,endtime);

Best Answer

If you are trying to integrate data, not functions, I recommend using TRAPZ instead of trying to create some sort of function (which may or may not agree well with your data) to use with INTEGRAL.