Running area under the curve at each time step.
조회 수: 1 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
ChristianW
2013년 2월 10일
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
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!