MATLAB: How to use ode45 with input vector

MATLABode45springvector input

I'm modeling a system mass spring damper and i have aceleration signal with 20200 values. Im testing with the 3 first values (-0.0120 ; -0.015 ; -0.0109) but ode45 is just using the value -0.0120. What can i do to use these 3 values ?
%MODELING NON-INERTIAL SYSTEM OF 2nd ORDER
% M x''(t) + b x'(t)+ k x(t) = f(t)
%acx = a(:,1)';
acx = [-0.0120 ; -0.015 ; -0.0109 ]';
cond.ini = [0 0];
[t, x] = ode45(@daceler, t, cond.ini, [] , acx);
plot(t,x);
function f = daceler(~,x,acx)
f = zeros (2,1);
b=0.01;
k=0.18;
m=0.005;
i = length (3);
f(1)=x(2);
f(2)=-(b/m)*x(2)-(k/m)*x(1)+((1/m)*acx(1:i));
end

Best Answer

You have
i = length (3);
length(3) is length of the 1 x 1 array whose numeric value is 3, and that length is 1, so i will be assigned one, and then acx(1:i) will be acx(1:1)
If you were to change that to something like
i = length(acx)
then you would be computing a vector of values on the right side of the f(2) assignment, which would be a problem because the storage location f(2) only has room for one value.
Note: you are relying upon a syntax for ode45 that has not been documented in over a decade. You should parameterize the function instead.
Related Question