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

3 ビュー (過去 30 日間)
wd w
wd w 2024 年 2 月 23 日
編集済み: Voss 2024 年 2 月 27 日
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 件のコメント
Mathieu NOE
Mathieu NOE 2024 年 2 月 27 日
hello
it would be more efficient to share your data and code , so someone can work on your problem

サインインしてコメントする。

回答 (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 Center および File ExchangeInterpolation についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by