Uniform grid index
returns the index of the value
indx = val2ind(
val in a uniform grid with a spacing
between elements of
delta. The first element of the uniform grid is
val does not correspond exactly to an element of the grid, the
next element is returned. If
val is a vector, then
indx is a vector of the same size.
Compute Index of Value in Grid
Find the index corresponding to 0.0001 in a uniform grid with 1 MHz sampling rate.
fs = 1e6; indx = val2ind(0.0001,1/fs)
indx = 101
Compute Indices of Values in Grid
Find the indices corresponding to a vector of values in a uniform grid with 1 kHz sampling rate. Values are not divisible by 1/fs.
fs = 1.0e3; values =[0.0095 0.0125 0.0225]; indx = val2ind(values,1/fs)
indx = 1×3 11 14 24
val — Data values
scalar | vector
Data values, specified as a scalar or vector.
[3.4 6.3 9.8 12.1]
delta — Spacing between grid elements
Spacing between grid elements, specified as a positive scalar.
startval — Starting value of the uniform grid
0 (default) | real scalar
Starting value of the uniform grid, specified as a scalar
startval must be smaller than or equal to the minimum value in
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
Does not support variable-size inputs.
Introduced in R2011a