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

3 visualizzazioni (ultimi 30 giorni)
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.

Risposte (1)

Voss
Voss il 27 Feb 2024
Modificato: Voss il 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'})

Categorie

Scopri di più su Interpolation in Help Center e File Exchange

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by