Function to return Interpolated Value at one query point
조회 수: 13 (최근 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');
!-----------------------------------------------
댓글 수: 0
채택된 답변
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')
F = griddedInterpolant(z2);
xp = 0.001237;
yp = 0.002954;
zp1 = F(xp, yp)
% 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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
