For your sample data, this works:
x=[0 1 2 3 4 4 5 6 7 7 8 9 10 11 12 13 14 14 15 16 17 18 19 20];
y=[1 2 5 3 4 8 6 5 8 5 8 6 85 85 66 44 55 66 88 77 99 88 55 66];
xi=[0 5 10 15 20];
dup = find(diff([eps x]) == 0);
x(dup) = x(dup)+1E-8;
yi = interp1(x, y, xi, 'linear', 'extrap');
yi =
1 6 85 88 66
If you have more than one repeated consecutive ‘x’ value, this gets a bit more involved, but the same approach applies.
Best Answer