Function to return Interpolated Value at one query point

11 次查看(过去 30 天)
I have created an interpolation surface of my experimental data (xA,yA,zA) to a grid with the code below, and now would like to create a function to return the interpolated value at a given single querry point, for example (.001237, .002954).
How can I create an F(x,y) that will return a single value, the interpolated value of z at the point (x,y)?
!---------------------------------------------
[xq,yq] = meshgrid(.001:.00005:.005);
z2 = griddata(xA,yA,zA,xq,yq,'cubic');
!-----------------------------------------------

采纳的回答

Star Strider
Star Strider 2022-4-8
Use the griddedInterpolant function, and then experiment with the actual data to see what gives the best results —
xA = (rand(20,1))*0.005;
yA = (rand(20,1))*0.005;
zA = (rand(20,1))*0.005;
[xq,yq] = meshgrid(.001:.00005:.005);
z2 = griddata(xA,yA,zA,xq,yq,'cubic')
z2 = 81×81
0.0020 0.0019 0.0019 0.0018 0.0018 0.0017 0.0016 0.0018 0.0021 0.0021 0.0020 0.0020 0.0019 0.0018 0.0018 0.0017 0.0016 0.0016 0.0015 0.0014 0.0013 0.0012 0.0010 0.0009 0.0008 0.0007 0.0006 0.0005 0.0004 0.0004 0.0020 0.0020 0.0019 0.0019 0.0018 0.0017 0.0019 0.0021 0.0021 0.0021 0.0020 0.0019 0.0019 0.0018 0.0018 0.0017 0.0016 0.0015 0.0014 0.0014 0.0012 0.0011 0.0010 0.0009 0.0008 0.0007 0.0006 0.0005 0.0004 0.0004 0.0021 0.0020 0.0020 0.0019 0.0018 0.0021 0.0022 0.0022 0.0021 0.0021 0.0020 0.0019 0.0019 0.0018 0.0017 0.0016 0.0016 0.0015 0.0014 0.0013 0.0012 0.0011 0.0010 0.0009 0.0008 0.0007 0.0005 0.0005 0.0004 0.0004 0.0021 0.0021 0.0020 0.0019 0.0022 0.0023 0.0022 0.0022 0.0021 0.0020 0.0020 0.0019 0.0018 0.0018 0.0017 0.0016 0.0015 0.0015 0.0014 0.0013 0.0012 0.0011 0.0010 0.0009 0.0008 0.0006 0.0005 0.0005 0.0004 0.0004 0.0022 0.0021 0.0021 0.0023 0.0023 0.0022 0.0022 0.0021 0.0021 0.0020 0.0019 0.0019 0.0018 0.0017 0.0016 0.0016 0.0015 0.0014 0.0013 0.0013 0.0012 0.0011 0.0010 0.0009 0.0008 0.0006 0.0005 0.0005 0.0004 0.0004 0.0022 0.0022 0.0024 0.0023 0.0023 0.0022 0.0022 0.0021 0.0020 0.0020 0.0019 0.0018 0.0017 0.0017 0.0016 0.0015 0.0014 0.0014 0.0013 0.0012 0.0011 0.0010 0.0010 0.0009 0.0007 0.0006 0.0005 0.0004 0.0004 0.0004 0.0023 0.0024 0.0024 0.0023 0.0023 0.0022 0.0021 0.0021 0.0020 0.0019 0.0018 0.0018 0.0017 0.0016 0.0015 0.0015 0.0014 0.0013 0.0012 0.0012 0.0011 0.0010 0.0009 0.0008 0.0007 0.0006 0.0005 0.0004 0.0004 0.0003 0.0025 0.0024 0.0024 0.0023 0.0022 0.0022 0.0021 0.0020 0.0019 0.0019 0.0018 0.0017 0.0016 0.0016 0.0015 0.0014 0.0013 0.0013 0.0012 0.0011 0.0010 0.0010 0.0009 0.0008 0.0007 0.0006 0.0005 0.0004 0.0004 0.0003 0.0025 0.0024 0.0023 0.0023 0.0022 0.0021 0.0020 0.0020 0.0019 0.0018 0.0017 0.0016 0.0016 0.0015 0.0014 0.0013 0.0013 0.0012 0.0011 0.0011 0.0010 0.0009 0.0008 0.0008 0.0007 0.0006 0.0005 0.0004 0.0004 0.0003 0.0025 0.0024 0.0023 0.0022 0.0021 0.0021 0.0020 0.0019 0.0018 0.0017 0.0017 0.0016 0.0015 0.0014 0.0014 0.0013 0.0012 0.0011 0.0011 0.0010 0.0009 0.0009 0.0008 0.0007 0.0007 0.0006 0.0005 0.0004 0.0004 0.0003
F = griddedInterpolant(z2);
xp = 0.001237;
yp = 0.002954;
zp1 = F(xp, yp)
zp1 = 0.0020
% zp2 = F(yp, xp)
figure
surf(xq,yq,z2)
hold on
stem3(xp, yp, zp1, '^r', 'MarkerSize',10, 'MarkerFaceColor','r')
% stem3(yp, xp, zp2, '^g', 'MarkerSize',10, 'MarkerFaceColor','g')
hold off
xlabel('x')
ylabel('y')
view(-45,30)
It would help to have the actual data.
.
  2 个评论
Thomas Kane
Thomas Kane 2022-4-8
Thank you! This is just what I was looking for. Yes, I will experiment with the interpolation type to fine tune. Your code and the beautiful graphic are wonderfully illustrative. Thanks again.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by