function theta_out = fcn(t, theta_in)
%#eml

%Convert t (ms) to time (s)
time = double(t) / double(1000);

%Time scaling factor (# of trajectory points per second)
scaling = double(30);

%Compute the current index in the trajectory array
index_fraction = scaling*time + 1;
index = floor(index_fraction);
frac_add = index_fraction - index; % additional amount "beyond" index

%Extract the current position from the trajectory
if (index < length(theta_in))
    theta_out = (1-frac_add)*double(theta_in(index)) + ...
        frac_add*double(theta_in(index+1));
else %If we run out of data, continue outputting the last value
    theta_out = double(theta_in(length(theta_in)));
end
