interp1 result not close to sampled curve with rather simple data

Hello everyone,
might be a simple question, I am using the interp1 function to resample a curve but the resulting curve is not even close to the input data:
Brownish one is the input curve, yellow/blue are the Results for Makima or linear interpolation. Here is the an mwe code with the used Data:
%% x values of the curve
x = [0.0127 0.0168 0.0279 0.0409 0.0561 0.0717 0.0863 0.0995 0.1103 0.1185 0.1250];
%% y values of the curve
y = [0 0.0247 0.0528 0.0784 0.1047 0.1280 0.1491 0.1637 0.1732 0.1787 0.1816];
%% sampling interval
interval = [0 0.0090 0.0181 0.0272 0.0363 0.0454 0.0545 0.0636 0.0727 0.0817 0.0951 0.1102 ...
0.1250 0.1392 0.1517 0.1620 0.1698 0.1752 0.1788 0.1816];
%% Resampling at interval points
x_val_sampled = interp1(y,x,interval,'makima');
plot(x,y,x_val_sampled(1:10),x_val_sampled(11:20))
Probably something small I am missing but I cant seem to figure it out by myself. Thanks for your time!

 Accepted Answer

The plot call is wrong.
It should be something like:
plot(x,y, x_val_sampled(11:20), interval(11:20))
Try this —
%% x values of the curve
x = [0.0127 0.0168 0.0279 0.0409 0.0561 0.0717 0.0863 0.0995 0.1103 0.1185 0.1250];
%% y values of the curve
y = [0 0.0247 0.0528 0.0784 0.1047 0.1280 0.1491 0.1637 0.1732 0.1787 0.1816];
%% sampling interval
interval = [0 0.0090 0.0181 0.0272 0.0363 0.0454 0.0545 0.0636 0.0727 0.0817 0.0951 0.1102 ...
0.1250 0.1392 0.1517 0.1620 0.1698 0.1752 0.1788 0.1816];
%% Resampling at interval points
x_val_sampled = interp1(y,x,interval,'makima');
plot(x,y, x_val_sampled(11:20), interval(11:20),'p-')
.

More Answers (0)

Products

Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!