MATLAB: How can i calculate area under curve from CSV file.

areaarea under curvecalculatecsvev chargerintegralshaded areatrapz

I wanna get the shaded area from the data that i've just conducted from my experiment in CSV file (Excel)
This is my code
figure
t=Time;
p = plot(t,ActivePowerANAvg)
title('Active Power (Box1)');
legend({'EV Charger'},'Location','northeast');
xlabel('Duration (h)') ;
ylabel('P (W)') ;
Integral = trapz(t,ActivePowerANAvg)
and the result that's shown in Command Window is
Integral =
duration
15648:04:10
Pls help me correct it.Thanks for all of you guys in advance.
The graph that i want to calculate the shaded area.

Best Answer

It would help to see the .csv file.
Apparently, ‘t’ was converted to a duration array in the process of reading it.
Try this:
t = minutes(1:200); % Duration Array
ActivePowerANAvg = [zeros(1,50) ones(1,100)*6500 zeros(1,50)]; % Create Vector
tv = datenum(t); % Convert To Numeric VEctor
Integral = cumtrapz(tv,ActivePowerANAvg); % Integrate (Using ‘cumtrapz’ For The Plot)
figure
yyaxis left
plot(t, ActivePowerANAvg) % Plot Signal As Duration
yyaxis right
plot(t, Integral) % Plot Integral As Duration
I use cumtrapz for the plot, use trapz to get only the end result. The code is otherwise the same.
EDIT — (13 Mar 2021 at 15:00)
Added plot figure —
.