MATLAB: Area Under Curve (or Between Curve)

areaarea under curve

How to find area under curve, I try trapz, not working.
sample=data(:,2); w=data(:,3); z=13.2 plot(sample, w, sample, z); area(w,z)
how to calculate area of shaded region?

Best Answer

I understand the time reference is in sample=data(:,2)
the function to integrate is in w=data(:,3) correct?
and the z=13.2 is some kind of squelch you want to remove while integrating? there is no need to plot 2 functions.
The area you are looking for is trapz(sample,w)
you have assigned z a scalar, but it should match the length of the data to integrate.
The integration goes from around 15 to 250, so the reference vector is tref=[15:1:250]
if you really want to remove those 13.2 (volts?) while integrating, this DC is actually
13.2*ones(1,length(tref)) so if you want to use two trapz, then
trapz(sample,w)-z*ones(1,length(tref))
does it make sense?
regards
John
Related Question