I would not do the interpolation this way. Instead, I would find x(t) and y(t), i.e., interpolate both x and y in terms of some common parameter t.
In fact, since you already have x and y as vectors of the same length (for a given motion), you can say t is the sample number and it is equivalent actual time assuming a constant sampling interval (probably a safe assumption). So the interpolation is easier that what you have now:
%load the data: xpos & ypos
load('pos_data.mat')
num_movements = numel(xpos);
%create cell array that will hold interpolated data
x_interp = cell(size(xpos));
y_interp = cell(size(ypos));
%construct grid vector
ypos_grid = [0:0.05:10];
num_interp_samples = length(ypos_grid);
%loop through each movement
for k=1:num_movements
%get data for the current movement
xp = xpos{k};
yp = ypos{k};
t = 1:length(yp);
ti = linspace(1,length(yp),num_interp_samples);
x_interp{k} = interp1(t, xp, ti);
y_interp{k} = interp1(t, yp, ti);
end
Plot the actual data and interpolated data as y vs x:
figure();
subplot(1,2,1);
hold on;
for k=1:num_movements
plot(xpos{k}, ypos{k}, 'color', 'k');
end
xlabel('x-position (cm)');
ylabel('y-position (cm)');
title('raw data');
subplot(1,2,2);
hold on;
for k=1:num_movements
plot(x_interp{k}, y_interp{k}, 'color', 'k');
end
xlabel('x-position (cm)');
ylabel('y-position (cm)');
title('interpolated data');
Now you can see the curvature is preserved.
This doesn't get you x(y), but it does allow you to compare the trajectories across multiple motions.