interpolate without unique in matlab

If you have a set of points that are not unique, and you want to interpolate a function over those points, the simplest way is to use the scatter function to plot the points, and then use the interp1 function to interpolate between them.

main.m
x = [0, 1, 1, 2, 3];
y = [1, 2, 2, 3, 4];
scatter(x, y);
xq = linspace(0, 3, 100);
yq = interp1(x, y, xq, 'spline');
hold on;
plot(xq, yq);
140 chars
8 lines

This will plot the original set of points, and then interpolate a smooth curve between them using the spline option in interp1. You can choose different options in interp1 to control the type of interpolation.

related categories

gistlibby LogSnag