Problems using trapz() - dimension issue

7 次查看(过去 30 天)
clc
clear all;
Az=load('TEXT PILOT CC LANKLE_converted_1.txt');
Az1=Az(:,1);%looking at the velocity in x first
A = length(Az1);
time = (length(Az1)/40); % the amount of time the device was switched on for
t = 0:(1/40):time; % seperating time properly
Az2=(Az1*9.81);%converting the data into m/s^2
vz = trapz(t,Az2);
plot(vz)
I am trying to integrate discrete data from an accelerometer so that I can plot a graph for the velocity I have attempted this a number of ways including using trapz(). I use the code above but I get the following error,
??? Error using ==> trapz at 59
LENGTH(X) must equal the length of the first non-singleton dimension of Y.
Error in ==> test_velocityusingtrap2 at 10
vz = trapz(t,Az2);
any ideas would be great!

采纳的回答

Matt J
Matt J 2014-1-13
t=linspace(0,time,length(Az2));
  2 个评论
Matt J
Matt J 2014-1-16
Bran's Comment relocated,
Hi there thank you so much this has resolved my dimensions problem however, the plot I get for velocity using trapz() isn't very meaningful is this code more useful
clc clear all;
Az=load('converted_1.txt');
Az1=Az(:,1);%looking at the velocity in x first A = length(Az1); time = (length(Az1)/40); % the amount of time the device was switched on for
t=linspace(0,time,A); % seperating time properly
Az2=(Az1*9.81);%converting the data into m/s^2
Az3 = padarray(Az2,[0 3],'post');
vz(length(Az1),:)=0; % setting out a vector containing zero's to then fill
i=1;
while (i<A)
vz(i)=((t(i+1)-t(i))*((Az3(i)+Az3(i+1))/2));
i=i+1;
end
Also I am confused about what I shoud be using for the inital conditions do I need to add vz(i) to my calcualtions as well, I thought I just need to add v(0) to each which I am assuming to be zero? plot(vz)
Matt J
Matt J 2014-1-16
Yes, it sounds like you would add v(0).

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by