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

3 次查看(过去 30 天)
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 个)

Voss
Voss 2024-2-27
编辑:Voss 2024-2-27
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'})

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by