필터 지우기
필터 지우기

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 CenterFile Exchange에서 Polynomials에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by