Problems using trapz() - dimension issue

조회 수: 3 (최근 30일)
Bran
Bran 2014년 1월 13일
댓글: Matt J 2014년 1월 16일
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