フィルターのクリア

Linear Interpolation listed data points on to anothe list

4 ビュー (過去 30 日間)
root
root 2023 年 12 月 3 日
コメント済み: Image Analyst 2023 年 12 月 3 日
I have range of measurments as shown
x_data = (0.7127, 0.6954, 0.6789, 0.6744, 0.6697, 0.6649, 0.6600, 0.6551, 0.6501, 0.6450,
0.7127, 0.7091, 0.6988, 0.6827, 0.6626, 0.6574, 0.6520, 0.6466, 0.6411, 0.6356,
0.6300, 0.6245, 0.6190)
I want to interpolate (linear) the above x data on to new unformly spaced z value given by:
z_new = 0:10/6371:0.244
Given that the x list has differnet length than the new data (z) how do we do this interpolation?
I tried this from mathworks online but not working:
"vq = interp1(x,v,xq) returns interpolated values of a 1-D function at specific query points using linear interpolation. Vector x contains the sample points, and v contains the corresponding values, v(x). Vector xq contains the coordinates of the query points"
Thank you

採用された回答

Image Analyst
Image Analyst 2023 年 12 月 3 日
You're mixing up x_data, x, z_new, and v. I think the nomenclature is confusing you. Try this:
x_data = [0.7127, 0.6954, 0.6789, 0.6744, 0.6697, 0.6649, 0.6600, 0.6551, 0.6501, 0.6450,...
0.7127, 0.7091, 0.6988, 0.6827, 0.6626, 0.6574, 0.6520, 0.6466, 0.6411, 0.6356,...
0.6300, 0.6245, 0.6190];
x = 1 : numel(x_data);
v = x_data;
subplot(2, 1, 1);
plot(x, v, 'b.--', 'LineWidth', 2, 'MarkerSize', 20)
grid on;
xlabel('Index', 'Interpreter','none');
ylabel('x_data', 'Interpreter','none')
% This z_new is no good since the interpolation x values are
% not in the range of x_data indexes.
z_new = 0:10/6371:0.244; % BAD!
size(z_new)
ans = 1×2
1 156
% Let's use a z_new that goes from the first index
% to the first index + 0.244, in other words in the range [1, 1.244]
% And since the original z_new had 156 points, let's use 156 points
% with the new z_new.
z_new = linspace(1, 1.244, 156);
vq = interp1(x,v,z_new);
subplot(2, 1, 2);
x = 1 : numel(vq);
plot(x, vq, 'r-', 'LineWidth', 2)
grid on;
title('vq', 'Interpreter','none');
xlabel('Index', 'Interpreter','none');
ylabel('Interpolated x_data', 'Interpreter','none')
If that is not the interpolation region you want, feel free to set the z_new range anywhere from 1 to 23 (which is the number of elements in x_data).
  4 件のコメント
root
root 2023 年 12 月 3 日
Thanks for your clarification .
The data to be interpolated is the given x_data. I want to interpolate this on znew where znew has a value if 0:max(x_data) with stepsize of 10/6371.
Image Analyst
Image Analyst 2023 年 12 月 3 日
That does not make any sense. Please show on a numberline or a graph the actual x_data points, and the values for which you want interpolated as your output. Keep in mind that any points specified outside the range of your input data will be NaN.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by