Calculating the error between true point and interpolation

6 ビュー (過去 30 日間)
Christian Mathiesen
Christian Mathiesen 2021 年 10 月 7 日
Hi. I have 35 points where x is distance in meters, and z is seismic depth in seconds. I have made a 1d spline and k-nearest interpolation between these points, and I'm now trying to calculate the error. However, I'm having trouble calculating the difference in z between the real (the red dot) and corresponding interpolated point (blue line at the same x-position as the red dot). I've tried the following, but it doesn't work.
Thanks in advance.
clc; close all;
td = load("thicknesses.dat");
x = td(:,1);
z = td(:,3);
n_x = length(x);
end_x = x(end);
x_sample = linspace(x(1),end_x,n_x);
spline_int = interp1(x,z,x_sample,'spline');
k_nearest_int = interp1(x,z,x_sample,'nearest');
figure();
subplot(1,2,1);
plot(x,z,'or');
set(gca, 'YDir','reverse')
hold on;
plot(x_sample, spline_int, '-b');
title('spline', 'FontSize',15)
xlabel('Distance in x-direction (m)','FontSize',10)
ylabel('Thickness (s)','FontSize',10)
subplot(1,2,2);
plot(x,z,'or');
set(gca, 'YDir','reverse')
hold on;
plot(x_sample, k_nearest_int, '-b');
title('k-nearest', 'FontSize',15)
xlabel('Distance in x-direction (m)','FontSize',10)
ylabel('Thickness (s)','FontSize',10)
hold off;
spline_at_x = [];
for i = 1:length(x);
k(i) = spline_int(i(x_sample == x(i)))
spline_at_x = [spline_at_x k(i)]
end
end
Hope it is clear, thanks in advance.

採用された回答

Image Analyst
Image Analyst 2021 年 10 月 7 日
Unfortunately you forgot to attach "thicknesses.dat" so we can't run your code. Why can't you simply say
differences = spline_at_x - x;
Take the absolute value if you want.
  1 件のコメント
Christian Mathiesen
Christian Mathiesen 2021 年 10 月 7 日
Hi, thanks for your response. I actually ended up using fittype('smoothingspline') to get the residuals instead. Seemed simpler than what I had going on. Thanks for taking the time.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by