Interpolation of matrix with data that is of different dimensions

3 次查看(过去 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