Problems using trapz() - dimension issue

1 view (last 30 days)
Bran
Bran on 13 Jan 2014
Commented: Matt J on 16 Jan 2014
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!

Accepted Answer

Matt J
Matt J on 13 Jan 2014
t=linspace(0,time,length(Az2));
  2 Comments
Matt J
Matt J on 16 Jan 2014
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 on 16 Jan 2014
Yes, it sounds like you would add v(0).

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!