# Interpolating evenly spaced 2d matrix from 3 arrays

조회 수: 6(최근 30일)
Aaron Greenbaum 20 Jan 2017
답변: John D'Errico 20 Jan 2017
I have 3 161x1 arrays that should map to a 161 single points on a matrix, zprime array indicating the x location, yprime the y location, and xprime the depth. None of the values are integers. I then need to create a matrix that interpolates between these points.
I think that meshgrid might be the way to do it, but I'm having a trouble inputting it to make the matrix I want. Here is an example of how I made my arrays.
for n = 1:size(R,1)
xprime(n)=R(n)*cosd(cdata{6}(n))+cdata{3}(n);
yprime(n)=R(n)*sind(90-cdata{7}(n))*sind(cdata{6}(n))+cdata{4}(n);
zprime(n)=R(n)*sind(90-cdata{7}(n))*cosd(cdata{6}(n))+cdata{5}(n);
% 3dvar(n)={zprime(n),yprime(n),zprime(n)};
end
edit, I realize the interpolate may not be the correct word, once I have the data set, I want to fill in the remaining empty cells in the matrix so the data follows the curve.

댓글을 달려면 로그인하십시오.

### 답변(2개)

Walter Roberson 20 Jan 2017
together with ndgrid() or meshgrid(), and invoke the interpolant on the grid.

#### 댓글 수: 0

댓글을 달려면 로그인하십시오.

John D'Errico 20 Jan 2017
Assuming this corresponds to a single valued function, thus z(x,y), you can use triscatteredinterp or scatteredinterpolant as Walter suggested. Not that those tools will not extrapolate, so if the corners are missing, this is why, because your data did not extend to the corners of the desired lattice.
You can also use my gridfit to create the surface. Again, the data must correspond to a single valued functional form z(x,y).

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

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

Start Hunting!