How can I interpolate a data set to fill a missing point in a vector using MATLAB?
2 views (last 30 days)
Show older comments
How can I interpolate a data set to fill a missing point in a vector using MATLAB?
If I have values for a function on many of the data points on a grid and want to fill in the values of that function for the missing data points on the grid, what function should I use, and how should I set this up?
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
The following code evaluates the sample function
f(x,y,z) = x+2*y+4*z
on most of the integer-valued grid points on the unit cube, and uses those function values to interpolate the function value on an integer-valued grid point for which we do not have the function value.
% Generate data for the unit cube
[xx,yy,zz]=ndgrid(-1:1,-1:1,-1:1);
% Combine the three individual coordinates into a matrix
R=[xx(:) yy(:) zz(:)];
% Remove the entry for (1, -1, 1)
R(23,:)=[];
% Calculate a function on the given points
v = xx.*yy+2*xx.*zz+4*yy.*zz;
% Remove the point corresponding to (1, -1, 1)
v = v(:);
v(23, :) = [];
% Interpolate
% The duplicate entry as the third argument is due to
% a bug in griddatan with respect to row vectors as third
% input arguments
s = griddatan(R, v, [1 -1 1;1 -1 1])
0 Comments
More Answers (0)
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!