fixed.interp3
Syntax
Description
returns interpolated values of a function of three variables at specific query points
using linear interpolation. The results always pass through the original sampling of the
function. Vq
= fixed.interp3(X,Y,Z
,V
,Xq,Yq,Zq
)X
, Y
, and Z
contain the
coordinates of the sample points. V
contains the corresponding function
values at each sample point. Xq
, Yq
, and
Zq
contain the coordinates of the query points.
Examples
Implement 3D FixedPoint Lookup Tables Using Interpolation
This example shows how to implement a threedimensional fixedpoint lookup table using fixed.interp3
.
Run the example multiple times to see the approximation over different query points.
Create Lookup Table for Function
Define a function f(x,y,z)
to replace with a lookup table approximation.
clearvars f = @(x,y,z) x.^2+y.^2y.*z;
Define breakpoints x
, y
, and z
for the lookup table. Note that m
, n
, and p
do not have to be equal and x
, y
, and z
do not have to be linearly spaced.
m = 16; n = 16; p = 16; x = linspace(5,5,n); y = linspace(5,5,m); z = linspace(5,5,p); [X,Y,Z] = meshgrid(x,y,z);
Generate lookup table values V
corresponding to the breakpoints.
V = f(X,Y,Z);
Query Lookup Table
Choose a random query point (xq,yq)
in the ranges of x
and y
.
xq = fixed.example.realUniformRandomArray(x(1),x(end),1); yq = fixed.example.realUniformRandomArray(y(1),y(end),1); zq = fixed.example.realUniformRandomArray(z(1),z(end),1);
Cast the inputs to 16bit fixedpoint.
X = fi(X); Y = fi(Y); Z = fi(Z); V = fi(V); xq = fi(xq); yq = fi(yq); zq = fi(zq);
The fixed.interp3
function computes vq
, the lookup table approximation of f(xq,yq,zq)
.
vq = fixed.interp3(X,Y,Z,V,xq,yq,zq)
vq = 21.7305 DataTypeMode: Fixedpoint: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 9
Compare Lookup Approximation to Actual Function Value
Compare vq
to the actual function evaluation f(xq,yq,zq)
.
vq_expected = f(double(xq),double(yq),double(zq))
vq_expected = 21.6975
err = double(vq)  vq_expected
err = 0.0330
Input Arguments
X,Y,Z
— Sample grid points
arrays  vectors
Sample grid points, specified as real arrays or vectors. The sample grid points must be strictly monotonically increasing in each dimension.
If
X
,Y
, andZ
are arrays, then they contain the coordinates of a full grid (inmeshgrid
format). Use themeshgrid
function to create theX
,Y
, andZ
arrays together. These arrays must be the same size.If
X
,Y
, andZ
are vectors, then they are treated as a grid vectors. The values in these vectors must be strictly monotonically increasing.
The inputs [X,Y,Z]
, V
, and
[Xq,Yq,Zq]
must be the same data type: fi
,
half
, single
, or double
. When
using fi
data, you can use the shortened function name
interp3
.
Example: [X,Y,Z] = fi(meshgrid(1:30,10:10,1:5))
Example: [X,Y,Z] = half(meshgrid(1:30,10:10,1:5))
Data Types: fi
 single
 double
V
— Sample values
array
Sample values, specified as a real or complex array. The size requirements for
V
depend on the size of X
, Y
,
and Z
:
If
X
,Y
, andZ
are arrays representing a full grid (inmeshgrid
format), then the size ofV
matches the size ofX
,Y
, orZ
.If
X
,Y
, andZ
are grid vectors, thensize(V) = [length(Y) length(X) length(Z)]
.
If V
contains complex numbers, then
fixed.interp3
interpolates the real and imaginary parts
separately.
The inputs [X,Y,Z]
, V
, and
[Xq,Yq,Zq]
must be the same data type: fi
,
half
, single
, or double
. When
using fi
data, you can use the shortened function name
interp3
.
Example: fi(rand(10,10,10),0,12,8)
Example: half(rand(10,10,10))
Data Types: fi
 single
 double
Complex Number Support: Yes
Xq,Yq,Zq
— Query points
scalars  vectors  arrays
Query points, specified as a real scalars, vectors, or arrays.
If
Xq
,Yq
, andZq
are scalars, then they are the coordinates of a single query point in R^{3}.If
Xq
,Yq
, andZq
are vectors of different orientations, thenXq
,Yq
, andZq
are treated as grid vectors in R^{3}.If
Xq
,Yq
, andZq
are vectors of the same size and orientation, thenXq
,Yq
, andZq
are treated as scattered points in R^{3}.If
Xq
,Yq
, andZq
are arrays of the same size, then they represent either a full grid of query points (inmeshgrid
format) or scattered points in R^{3}.
The inputs [X,Y,Z]
, V
, and
[Xq,Yq,Zq]
must be the same data type: fi
,
half
, single
, or double
. When
using fi
data, you can use the shortened function name
interp3
.
Example: [Xq,Yq,Zq] =
fi(meshgrid((1:0.1:10),(5:0.1:0),3:5))
Example: [Xq,Yq,Zq] =
half(meshgrid((1:0.1:10),(5:0.1:0),3:5))
Data Types: fi
 single
 double
method
— Interpolation method
"linear"
(default)  "nearest"
Interpolation method, specified as one of the options in this table.
Method  Description  Continuity  Comments 

"linear"  The interpolated value at a query point is based on linear interpolation of the values at neighboring grid points in each respective dimension. This method is the default interpolation method.  C^{0} 

"nearest"  The interpolated value at a query point is the value at the nearest sample grid point.  Discontinuous 

extrapval
— Function value outside domain of X
, Y
, and Z
scalar
Function value outside the domain of X
, Y
, and
Z
, specified as a real or complex scalar.
fixed.interp3
returns this constant value for all points outside
the domain of X
, Y
, and Z
. If
the scalar value is nonzero and outside the range of the sample values
v
, then the value is set to the minimum or maximum value of
v
, whichever is closer.
The data type of extrapval
must be the same as
[X,Y,Z]
, V
, and
[Xq,Yq,Zq]
.
The default behavior with fi
input data is to return
0
for query points outside the domain. The default behavior with
half
, single
, or double
input
data is to return NaN
for query points outside the domain.
Example: fi(5)
Example: half(5+1i)
Data Types: fi
 single
 double
Complex Number Support: Yes
Note
The default behavior of the interp3
function is to return
NaN
when a query point is outside the domain. The
fixed.interp3
function with fi
input data is not
consistent with this behavior because fi
casts NaN
to 0
.
Output Arguments
Vq
— Interpolated values
scalar  vector  array
Interpolated values, returned as a real or complex scalar, vector, or array. The
size and shape of Vq
depends on the syntax you use and, in some
cases, the size and value of the input arguments. The data type of Vq
is the same as that of the sample values V
.
Syntaxes  Special Conditions  Size of Vq  Example 

fixed.interp3(X,Y,Z,V,Xq,Yq,Zq) ,fixed.interp3(V,Xq,Yq,Zq) ,and variations of these syntaxes that include method or
extrapval  Xq , Yq , and Zq
are scalars.  Scalar  size(Vq) = [1 1] when you pass Xq ,
Yq , and Zq as scalars. 
Same as above  Xq , Yq , and Zq
are vectors of the same size and orientation.  Vector of same size and orientation as Xq ,
Yq , and Zq  If size(Xq) = [100 1] , and size(Yq) = [100 1] , and size(Zq) = [100 1] , then size(Vq) = [100 1] . 
Same as above  Xq , Yq , and Zq
are vectors of mixed orientation.  size(Vq) = [length(Y) length(X) length(Z)]  If size(Xq) = [1 100] ,and size(Yq) = [50 1] , and size(Zq) = [1 5] ,then size(Vq)
= [50 100 5] . 
Same as above  Xq , Yq , and Zq
are arrays of the same size.  Array of the same size as Xq , Yq ,
and Zq  If size(Xq) = [50 25] ,and size(Yq) = [50 25] , and size(Zq) = [50 25] , then size(Vq) = [50 25] . 
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.
Version History
Introduced in R2024a
See Also
fixed.interp1
 fixed.interp2
 fixed.interpn
 meshgrid
 interp3
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
 América Latina (Español)
 Canada (English)
 United States (English)
Europe
 Belgium (English)
 Denmark (English)
 Deutschland (Deutsch)
 España (Español)
 Finland (English)
 France (Français)
 Ireland (English)
 Italia (Italiano)
 Luxembourg (English)
 Netherlands (English)
 Norway (English)
 Österreich (Deutsch)
 Portugal (English)
 Sweden (English)
 Switzerland
 United Kingdom (English)