integrate a partial area under a plotted curve
Show older comments
Hello every one,
I'm trying to calculate a partial area under a curve.
I've seen some asked questions about the subsject, but still struggling with some points.
I plotted a cuvre using numerical column vectors (electrical current versus time), then using this proposed solution, i tried to calculate the area under the curve:
yi = interp1(x, y, [x1:x2]); % x1 and x2 are the boundaries
shaded_area = trapz([4:5],yi+5)
Where y represents my electrical current vector and x my time vector, which contains by the way negative values, but i don't think that causes any problem.
When i execute the first line, it returns 'Nan' values!! So, I tried other column vectors which are extracted from the former ones (x and y) but i took only the positive values and again it returns NaN.
I thinking about extrapolating problem, but i have non idea about how to start with this issu?
It'll be very helpful if some one could give me some advice. Thank you!
Please find the attached source data file, function allowing importing data and the commands file (in the commands file, i changed the name of the dataset).
Using Matlab_2018b
8 Comments
darova
on 24 Feb 2020
Please make a simple drawing of the result you want

amirouche oumaziz
on 25 Feb 2020
darova
on 25 Feb 2020
So you want to find 2 points (red on my drawing)

amirouche oumaziz
on 25 Feb 2020
amirouche oumaziz
on 25 Feb 2020
darova
on 25 Feb 2020
What are those values?

amirouche oumaziz
on 25 Feb 2020
darova
on 25 Feb 2020
I think these are the same values?
endingIndex = find(x==x(indexMax));
I suggest you use this instruction
% startingIndex = find(x==-2*1e-6);
startingIndex = find(x>-2e-6,1,'first');
Why not '=='? Example
>> a = [1 2 1/3];
ix = find(a==0.333)
ix =
Empty matrix: 1-by-0
Accepted Answer
More Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


