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

3 vues (au cours des 30 derniers jours)
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.
  1 commentaire
Mathieu NOE
Mathieu NOE le 27 Fév 2024
hello
it would be more efficient to share your data and code , so someone can work on your problem

Connectez-vous pour commenter.

Réponses (1)

Voss
Voss le 27 Fév 2024
Modifié(e) : Voss le 27 Fév 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'})

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by