How to find area under plotted curve if given a vector containing numerical data?
8 views (last 30 days)
Show older comments
George Vuong
on 19 Nov 2015
Commented: Star Strider
on 20 Nov 2015
If given the following data set, a, for example, and vector a is plotted using the code provided below, how do I find the area under that curve? I understand that one way would be to determine the function of the plotted curve and integrating it. I would also have to define where the x-axis is at zero, so probably at 1150 would be where I want the positive x-axis to begin.. But if I go that route, does MATLAB have a way of determining the function of a plotted curve? Or is there a MATLAB function that would help me do all that and output the area under the curve???
a = [840.827393
880.441772
982.080688
1222.500488
1549.706665
1773.614624
1845.284546
1815.412964
1723.675903
1604.484131
1470.431763
1356.473511
1268.526978
1167.364990
1095.291504
1039.703857
1012.517639
1018.414062
1052.356323
1079.090698];
figure
plot(1:length(a),a)
grid on
axis([-inf inf min(min(a)) max(max(a))])
0 Comments
Accepted Answer
Star Strider
on 19 Nov 2015
I would use the trapz (or cumtrapz) function. They are most accurate when you supply a vector of your independent variables as well.
2 Comments
Star Strider
on 20 Nov 2015
As always, my pleasure.
If you have the independent variable vector that corresponds to the data in ‘a’, use it together in trapz or cumtrapz to get the result you want. It will be more accurate than the function assuming integer spacing, as it will if you supply it with only one argument.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!