Hi Vishwak,
I see that you are facing some errors in your code. It seems the problem comes from this line:
plot(c_t1(1:59), c_acc);
It seems you are trying to access “c_acc” up to index 59, which could be out of bounds. According to your code, “c_acc” is computed within this loop:
for i = 1:(length(c_vel) - 1)
c_acc_x(i) = ((c_vel_x(i+1) - c_vel_x(i)));
c_acc_y(i) = ((c_vel_y(i+1) - c_vel_y(i)));
c_acc = sqrt(c_acc_x(i)^2 + c_acc_y(i)^2);
end
The issue is that “c_acc” is being reassigned during each iteration, which means it only retains the last computed value instead of storing an array. To resolve this, modify your loop like this:
c_acc(i) = sqrt(c_acc_x(i)^2 + c_acc_y(i)^2);
This ensures that “c_acc” retains all computed values instead of only the most recent one.
For improved performance, it is advisable to preallocate memory for the arrays before entering the loop:
c_vel_x = zeros(1, length(c_t1) - 1);
c_vel_y = zeros(1, length(c_t1) - 1);
c_acc_x = zeros(1, length(c_t1) - 2);
c_acc_y = zeros(1, length(c_t1) - 2);
c_acc = zeros(1, length(c_t1) - 2);
Here is the output of the updated code:

