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?

2 commentaires

Torsten
Torsten le 8 Déc 2015
Why does trapz not work ?
What's the error message ?
Best wishes
Torsten.
Jena Jenna
Jena Jenna le 9 Déc 2015
I want to find area filled so, i try areaunder=trapz (sample,w)-trapz (sample, z). I got answer for trapz(sample,w) but not for trapz(sample,z) . error message was
??? Subscript indices must either be real positive integers or logicals.
Error in ==> ipermute at 23 inverseorder(order) = 1:numel(order); % Inverse permutation order
Error in ==> trapz at 78 if ~isempty(perm), z = ipermute(z,perm); end

Connectez-vous pour commenter.

 Réponse acceptée

John BG
John BG le 9 Déc 2015
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

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by