How can I do integral from discrete data points?

조회 수: 15 (최근 30일)
MathWorks Support Team
MathWorks Support Team 2018년 1월 24일
답변: MathWorks Support Team 2018년 2월 23일
I have data "x" and "y" stored as arrays in MATLAB. How can I evaluate the area under the curve just from my data?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2018년 1월 24일
You can first interpolate your data to get a function handle. Then, you can use "integral" to integrate your data:
1. Create 50 sample data to work with
>> n = 50;
>> x = linspace(0, 2*pi, n);
>> y = sin(x) + 0.1*randn(1,n);
 2. Plot the data to  visualize it
>> plot(x,y,'x');
 3. Create an interpolation of the data, and save it as a function handle:
>> F = griddedInterpolant(x,y);
>> fun = @(t) F(t)
 4. Plot the function to visualize:
>> plot(x, fun(x))
 5. Integrate the function with respect to x:
>> q = integral(fun, x(1), x(end))
 

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by