Interpolation of matrix with data that is of different dimensions

조회 수: 1 (최근 30일)
The code below attempts to interpolate from a matrix (13x10) which contains velocities corresponding to some x points(1x10) and y points (13x1). I need to find the velocity for the same 10 x points but with different y points (10x1). I have tried the following to interpolate the matrix, however, I can't get a code that runs. Am I using the correct technique? If so why isn't this working? And if not then I am grateful for any assistance.
x_points = [3,6,9,12,15,18,21,24,27,30]; % X values for the function
y_points = [1,2,3,4,5,6,7,8,9,10,11,12,13]; % Y values for the function
Yq = [12.7,11.16,11.68,10.99,12.98,3.61,9.291,0.18,9.86,3.64] % The points for which I need the function value
Xq = x_points
F = interp2(x_points,y_points,V1,x_points,interpolate_me); % Output the matrix withe the data

채택된 답변

Walter Roberson
Walter Roberson 2021년 3월 13일
편집: Walter Roberson 2021년 3월 13일
V1 = sort(randi(9,13,10));
x_points = [3,6,9,12,15,18,21,24,27,30]; % X values for the function
y_points = [1,2,3,4,5,6,7,8,9,10,11,12,13]; % Y values for the function
Yq = [12.7,11.16,11.68,10.99,12.98,3.61,9.291,0.18,9.86,3.64] % The points for which I need the function value
Yq = 1×10
12.7000 11.1600 11.6800 10.9900 12.9800 3.6100 9.2910 0.1800 9.8600 3.6400
Xq = x_points
Xq = 1×10
3 6 9 12 15 18 21 24 27 30
F = interp2(x_points,y_points,V1, Xq, Yq); % Output the matrix withe the data
F
F = 1×10
8.7000 7.1600 9.0000 8.0000 8.9800 2.6100 5.5820 NaN 5.8600 3.0000
The Nan is because the Y query 0.18 is before any define y coordinate.
  댓글 수: 2
James Rodriguez
James Rodriguez 2021년 3월 13일
Thank you so much! Works perfectly. If I wanted to run this for multiple functions (v1.v2...) , is there an efficent way of doing this? I tried to form one matrix with all the function matrices and run that but it will not give an ouput .
Walter Roberson
Walter Roberson 2021년 3월 13일
Not really. There is a temptation to say "use interp3" with the third coordinate being the function number, but the problem with that is that it will mix between functions. Though maybe if you used a third coordinate that was on a much larger scale then the mixing would be minimal.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by