Running area under the curve at each time step.

Hello,
In the problem that I am working on, I am given an x and y set of data. The x being the time and the y being ft/s^2. I need to find the running area under the curve because that will be the velocity, needless to say I am having some troubles. The code is below
My code:
clear;
A=csvread('exc2.csv') %read data file
x=A(:,1)
y=A(:,2)
for i=1:length(A) %run the length of the array
v(i)=trapz(x(i),y(i)) %integral at each point
end
plot(x,v) %plot integration over same time step
I get an error stating "ORDER contains an invalid permutation index."
Am I at all on the right track for trying to solve this?
Thank you.

답변 (1개)

ChristianW
ChristianW 2013년 2월 10일

0 개 추천

Your input to trapz is a single point, you want to input a line. And for n = length(x) acceleration points you can only get n-1 velocity points.
clear;
x = 0:10;
y = sin(x);
for i=2:length(x) %run the length of the array
v(i-1) = trapz(x(1:i),y(1:i)); % integral at each point
end
subplot(211),plot(x,y)
subplot(212),plot(x(2:end),v)

댓글 수: 2

Jozef
Jozef 2013년 2월 10일
A Thousand thank yous! hours were wasted, the solution was to simple...
I would suggest using cumtrapz instead of this loop.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

질문:

2013년 2월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by