0
votes

I need to extract data values for a particular coordinate from a meshgrid in MATLAB, my code is the following:

PaarX=Paar(:,1);
PaarX1=PaarX(1:20:length(PaarX));
PaarY=Paar(:,2);
PaarY1=PaarY(1:20:length(PaarY));
x=PaarX;
y=PaarY;
v=Paar(:,3);
[xi, yi]=meshgrid(PaarX1, PaarY1);
vq=griddata(x, y, v, xi, yi, 'cubic');

The PaarX, PaarY and v are the X, Y and Z values of the surface, with the Z values the values to be interpolated. PaarX1 and PaarY1 are the values used in the meshgrid with every 20th value taken (the array was too large before this). I need to extract interpolated Z values in vq from particular X and Y coordinates.

1

1 Answers

1
votes

As I understood your question, you need this:

nx = 3; % <= length(PaarX1)
ny = 4; % <= length(PaarY1)
fprintf('the interpolated value at x=%g and y=%g is %g',PaarX1(nx),PaarY1(ny),vq(ny,nx))

Or you can transpose the matrix vq

vq = vq.';
fprintf('the interpolated value at x=%g and y=%g is %g',PaarX1(nx),PaarY1(ny),vq(nx,ny))

vq(ny,nx) (y is first) is because you use the meshgrid function. You can use access to a matrix element in the form vq(nx,ny) (x is first) for the ndgrid function (but I'm not sure that it works with griddata).