0

I have data at the nodes of a 3D triangle, and I need to interpolate to get data inside the triangle.

here is what i tried to do:

  x=[0,1,0];
 y=[1,0,1];
 z=[0,2,-1];
 [X,Y,Z]=meshgrid(x,y,z);
 v=[2,5,-1];
 xs=linspace(0,1,.1);
 ys=linspace(0,1,.1);
 zs=linspace(-1,2,.1);
 Vs = interp3(X,Y,Z,v,xs,ys,zs,'linear');

i get an error: The number of input coordinate arrays does not equal the number of dimensions (NDIMS) of these arrays.

what is wrong?

1 Answers1

1

Let Xcontain the x-coordinates of your nodes, Y the y-coordinates, Z the z-coordinates of your nodes. Store the value/data at your nodes in V. Now you can specify where you want to interpolate the data by saving the x,y and z-coordinates of these points in Xs,Ys and Zs. The value of your data at these points is:

Vs = interp3(X,Y,Z,V,Xs,Ys,Zs,'linear');

You can take a look at the Matlab documentation.

Edit: As you added your code: The error seems to be that the dimension of your V is wrong. If you take a look at the example Matlab Docu -> interp3 -> Evaluate Outside the Domain of X, Y, and Z you will see, that Vhas to have the dimension as X, Yand Zcombined. From the documentation: size(V) = [length(Y) length(X) length(Z)] for vectors X ,Yand Z.

Here is an example:

X = linspace(-1,2,5);
Y = linspace(-1,7,23);
Z = linspace(3,9,23);
V = rand(23,5,23);

xq = linspace(0,1,34);
yq = linspace(0,2,34);
zq = linspace(4,5,34);
vq = interp3(X,Y,Z,V,xq,yq,zq,'linear',-1);
StefanM
  • 797
  • 1
  • 10
  • 17