How can I add query points between two adjacent points of sampled data and perform interpolation?

3 views (last 30 days)
I have a representative subset of sample points as shown above, and intend to define the query points to be a finer sampling over the range of x, for example, to add 10 query points (evenly) in interval of any two adjacent points in column A (x), then interpolate using the "linear" or "spline" method.

Answers (1)

Voss
Voss on 27 Feb 2024
Edited: Voss on 27 Feb 2024
Calculate the query points exactly as I showed in my answer to your other question
x = [-21.0598;-20.8076;-20.553;-20.307;-20.0533;-19.7929;-19.5517;-19.3;-19.0503;-18.777];
y = [-9.1948;-9.2299;-9.2583;-9.2909;-9.3189;-9.3527;-9.3784;-9.4144;-9.441;-9.4736];
n = 10; % number of points to insert in each interval
N = numel(x);
q = linspace(1,N,(n+1)*(N-1)+1);
Xq = interp1(1:N,x,q).'; % query points
Then interpolate:
% interpolated results:
Yq_linear = interp1(x,y,Xq);
Yq_spline = interp1(x,y,Xq,'spline');
Visualization of the results:
tiledlayout(2,1)
nexttile()
plot(x,y,'o')
hold on
plot(Xq,Yq_linear,'.-')
legend({'Data','Linear'})
nexttile()
plot(x,y,'o')
hold on
plot(Xq,Yq_spline,'.-')
legend({'Data','Spline'})

Categories

Find more on Interpolation in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!