Loop to calculate area under curve using rectangle methode
5 次查看(过去 30 天)
显示 更早的评论
Hello everyone I have a graph plotted in Matlab (no function), as data was imported via Excel, I am looking for a loop to calculate the area under the curve of each interval and then add them to get the entire area
Here's how my graph look like
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/189712/image.png)
2 个评论
Akira Agata
2018-4-18
How about using trapz function, instead of trying rectangle method. Or, do you have to try rectangle method for some reason?
回答(1 个)
Akira Agata
2018-4-23
Sorry for my late response. Here is an simple example.
% Sample data
dx = pi/10;
x = 0:dx:2*pi;
y = 1+sin(x);
% integral of y = f(x) via trapezoidal method (S1) and rectangle method (S2)
S1 = trapz(x,y);
S2 = sum(y*dx);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!