MATLAB: Intepolate in 2D loop of points

cloudinterpolation

Hi all,
I have a shape made up of regularly spaced data points in 2D. I want to increase the sampling of the points, i.e. interpolate between points as I need the outer edge in higher resolution than it is currently. I have tried intep etc, alphaShape and meshgrid but am struggling, so any help would be great. I have also tried just doing it for the points that make up the perimeter of the shape as this is what I'm interested in, but didn't get anywhere with that easier and thought it might be easier to do it as a whole object?
An example of a data set can be seen below.
%-2.57812500000000 -2.92968750000000
-2.57812500000000 -3.04687500000000
-2.57812500000000 -3.16406250000000
-2.57812500000000 -3.28125000000000
-2.57812500000000 -3.39843750000000
-2.57812500000000 -3.51562500000000
-2.57812500000000 -3.63281250000000
-2.57812500000000 -3.75000000000000
-2.57812500000000 -3.86718750000000
-2.57812500000000 -3.98437500000000
-2.46093750000000 -2.81250000000000
-2.46093750000000 -2.92968750000000
-2.46093750000000 -3.04687500000000
-2.46093750000000 -3.16406250000000
-2.46093750000000 -3.28125000000000
-2.46093750000000 -3.39843750000000
-2.46093750000000 -3.51562500000000
-2.46093750000000 -3.63281250000000
-2.46093750000000 -3.75000000000000
-2.46093750000000 -3.86718750000000
-2.46093750000000 -3.98437500000000
-2.34375000000000 -2.57812500000000
-2.34375000000000 -2.69531250000000
-2.34375000000000 -2.81250000000000
-2.34375000000000 -2.92968750000000
-2.34375000000000 -3.04687500000000
-2.34375000000000 -3.16406250000000
-2.34375000000000 -3.28125000000000
-2.34375000000000 -3.39843750000000
-2.34375000000000 -3.51562500000000
-2.34375000000000 -3.63281250000000
-2.34375000000000 -3.75000000000000
-2.34375000000000 -3.86718750000000
-2.22656250000000 -2.46093750000000
-2.22656250000000 -2.57812500000000
-2.22656250000000 -2.69531250000000
-2.22656250000000 -2.81250000000000
-2.22656250000000 -2.92968750000000
-2.22656250000000 -3.04687500000000
-2.22656250000000 -3.16406250000000
-2.22656250000000 -3.28125000000000
-2.22656250000000 -3.39843750000000
-2.22656250000000 -3.51562500000000
-2.22656250000000 -3.63281250000000
-2.22656250000000 -3.75000000000000
-2.22656250000000 -3.86718750000000
-2.10937500000000 -2.46093750000000
-2.10937500000000 -2.57812500000000
-2.10937500000000 -2.69531250000000
-2.10937500000000 -2.81250000000000
-2.10937500000000 -2.92968750000000
-2.10937500000000 -3.04687500000000
-2.10937500000000 -3.16406250000000
-2.10937500000000 -3.28125000000000
-2.10937500000000 -3.39843750000000
-2.10937500000000 -3.51562500000000
-2.10937500000000 -3.63281250000000
-2.10937500000000 -3.75000000000000
-2.10937500000000 -3.86718750000000
-1.99218750000000 -2.34375000000000
-1.99218750000000 -2.46093750000000
-1.99218750000000 -2.57812500000000
-1.99218750000000 -2.69531250000000
-1.99218750000000 -2.81250000000000
-1.99218750000000 -2.92968750000000
-1.99218750000000 -3.04687500000000
-1.99218750000000 -3.16406250000000
-1.99218750000000 -3.28125000000000
-1.99218750000000 -3.39843750000000
-1.99218750000000 -3.51562500000000
-1.99218750000000 -3.63281250000000
-1.99218750000000 -3.75000000000000
-1.87500000000000 -2.34375000000000
-1.87500000000000 -2.46093750000000
-1.87500000000000 -2.57812500000000
-1.87500000000000 -2.69531250000000
-1.87500000000000 -2.81250000000000
-1.87500000000000 -2.92968750000000
-1.87500000000000 -3.04687500000000
-1.87500000000000 -3.16406250000000
-1.87500000000000 -3.28125000000000
-1.87500000000000 -3.39843750000000
-1.87500000000000 -3.51562500000000
-1.87500000000000 -3.63281250000000
-1.87500000000000 -3.75000000000000
-1.75781250000000 -2.34375000000000
-1.75781250000000 -2.46093750000000
-1.75781250000000 -2.57812500000000
-1.75781250000000 -2.69531250000000
-1.75781250000000 -2.81250000000000
-1.75781250000000 -2.92968750000000
-1.75781250000000 -3.04687500000000
-1.75781250000000 -3.16406250000000
-1.75781250000000 -3.28125000000000
-1.75781250000000 -3.39843750000000
-1.75781250000000 -3.51562500000000
-1.75781250000000 -3.63281250000000
-1.75781250000000 -3.75000000000000
-1.64062500000000 -2.46093750000000
-1.64062500000000 -2.57812500000000
-1.64062500000000 -2.69531250000000
-1.64062500000000 -2.81250000000000
-1.64062500000000 -2.92968750000000
-1.64062500000000 -3.04687500000000
-1.64062500000000 -3.16406250000000
-1.64062500000000 -3.28125000000000
-1.64062500000000 -3.39843750000000
-1.64062500000000 -3.51562500000000
-1.64062500000000 -3.63281250000000
-1.64062500000000 -3.75000000000000
-1.52343750000000 -2.46093750000000
-1.52343750000000 -2.57812500000000
-1.52343750000000 -2.69531250000000
-1.52343750000000 -2.81250000000000
-1.52343750000000 -2.92968750000000
-1.52343750000000 -3.04687500000000
-1.52343750000000 -3.16406250000000
-1.52343750000000 -3.28125000000000
-1.52343750000000 -3.39843750000000
-1.52343750000000 -3.51562500000000
-1.52343750000000 -3.63281250000000
-1.40625000000000 -2.46093750000000
-1.40625000000000 -2.57812500000000
-1.40625000000000 -2.69531250000000
-1.40625000000000 -2.81250000000000
-1.40625000000000 -2.92968750000000
-1.40625000000000 -3.04687500000000
-1.40625000000000 -3.16406250000000
-1.40625000000000 -3.28125000000000
-1.40625000000000 -3.39843750000000
-1.40625000000000 -3.51562500000000
-1.40625000000000 -3.63281250000000
-1.28906250000000 -2.57812500000000
-1.28906250000000 -2.69531250000000
-1.28906250000000 -2.81250000000000
-1.28906250000000 -2.92968750000000
-1.28906250000000 -3.04687500000000
-1.28906250000000 -3.16406250000000
-1.28906250000000 -3.28125000000000
-1.28906250000000 -3.39843750000000
-1.28906250000000 -3.51562500000000
-1.28906250000000 -3.63281250000000
-1.17187500000000 -2.69531250000000
-1.17187500000000 -2.81250000000000
-1.17187500000000 -2.92968750000000
-1.17187500000000 -3.04687500000000
-1.17187500000000 -3.16406250000000
-1.17187500000000 -3.28125000000000
-1.17187500000000 -3.39843750000000
-1.17187500000000 -3.51562500000000
-1.17187500000000 -3.63281250000000
-1.05468750000000 -2.81250000000000
-1.05468750000000 -2.92968750000000
-1.05468750000000 -3.04687500000000
-1.05468750000000 -3.16406250000000
-1.05468750000000 -3.28125000000000
-1.05468750000000 -3.39843750000000
-1.05468750000000 -3.51562500000000
-1.05468750000000 -3.63281250000000
-0.937500000000000 -2.92968750000000
-0.937500000000000 -3.04687500000000
-0.937500000000000 -3.16406250000000
-0.937500000000000 -3.28125000000000
-0.937500000000000 -3.39843750000000
-0.937500000000000 -3.51562500000000
-0.937500000000000 -3.63281250000000
-0.820312500000000 -3.04687500000000
-0.820312500000000 -3.16406250000000
-0.820312500000000 -3.28125000000000
-0.820312500000000 -3.39843750000000
-0.820312500000000 -3.51562500000000
-0.820312500000000 -3.63281250000000
-0.703125000000000 -3.28125000000000
-0.703125000000000 -3.39843750000000
-0.703125000000000 -3.51562500000000
-0.703125000000000 -3.63281250000000
end

Best Answer

If I were you, I would throw away the data that is not on the edges by finding the min and max of each of your columns of data points. This takes advantage of the even spacing in your example dataset. If you don't have that nice spacing in your real data you could bin the values in x to achieve the same result.
Once you have two curves describing the top and bottom edges you can do whatever interpolation or smoothing you like. The code below will demonstrate a few options available to you.
% your example data is stored in the variable x (a 176x2 double array)
clf
plot(x(:,1),x(:,2),'.')
x0 = unique(x(:,1)); % get one value for each "column" of data
for ii = length(x0):-1:1 % for each column of data
these = x(:,1)==x0(ii); % find the corresponding indices
y0_lo(ii) = min(x(these,2)); % get the min y value (second column of x)
y0_hi(ii) = max(x(these,2)); % get the max y value
end
hold all
plot(x0,y0_lo,x0,y0_hi)
% interpolate to 100 points
x1 = linspace(min(x0),max(x0),100);
y1_lo = interp1(x0,y0_lo,x1,'spline');
y1_hi = interp1(x0,y0_hi,x1,'pchip');
plot(x1,y1_lo,x1,y1_hi)
% moving average with width 3 (from the Curve Fitting Toolbox)
y2_lo = smooth(y0_lo,3);
y2_hi = smooth(y0_hi,3);
plot(x0,y2_lo,x0,y2_hi)
hold off