MATLAB: Index out of bounds because of numel???

fevalnumelodeargumentsout of bounds

Hi,
I am having Problems with the below function and script.
function [ xdot ] = aq_1( t,x )
global m c k y
xdot(1) = x(2);
xdot(2) = (1/m)*((2*k*y)-c*x(2)-2*k*x(1));
xdot=[xdot(1);xdot(2)];
end
global m c k y
m=500*9.81;%Mass of object M = 500kg
c=400; %Dampening coefficient of shock absorber c = 400Ns/m
k=5; %Spring stiffness of each spring k = 5kN/m
tspan=[0:0.01:10];
b=0.05;%bump in metres
v=11.11;%velocity v = 40km/h or 11.11m/s
s=v*tspan;
w=2*pi/2;
y = b*sin(w*s);
[t,x]=ode45('aq_1',tspan,0);
plot(t,x(:,2))
This is the series of warnings I get below. I can't get my head around the first one of being out of bounds and can't find what a numel is.
I know it is a bit of an ask but I would appreciate the help.
Thanks
Attempted to access x(2); index out of bounds because
numel(x)=1.
Error in aq_1 (line 3)
xdot(1) = x(2);
Error in odearguments (line 88)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1}
to yp0.
Error in ode45 (line 114)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0,
odeArgs, odeFcn, ...

Best Answer

How did you call this function? Did you pass it an "x" with more than one element? Evidently not. Put this line as the first line in your function:
whos x
then look at this link: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/ which will help you more than you can imagine. It will give you great power at solving things like this.
Related Question