If the NaN values were at the leading and trailing (I assume at both ends) of your position-velocity matrix, and you are using the velocities to create your interpolation vector, you are likely extrapolating (or at least interp1 thinks so). See if changing the interp1 call to:
final_data(:,i) = interp1(other_data(:,1),other_data(:,2),x_interp, 'linear', 'extrap');
changes its behaviour. (You might want a different method than 'linear'. There are several to choose from, but if you extrapolate, you must specify a method.) Also, interp1 may not like the NaN values, so deleting the entries that have them may help get your code to work.
If you are still having problems with those changes, it could help if you uploaded a representative subset of the data that worked and the data that failed, along with the relevant part of the code you used in both situations. Did all of them have some NaN values in the velocity column?
Best Answer