Main Content


Uniform grid index


Ind = val2ind(Value,Delta)
Ind = val2ind(Value,Delta,GridStartValue)


Ind = val2ind(Value,Delta) returns the index of the value Value in a uniform grid with a spacing between elements of Delta. The first element of the uniform grid is zero. If Value does not correspond exactly to an element of the grid, the next element is returned. If Value is a row vector, Ind is a row vector of the same size.

Ind = val2ind(Value,Delta,GridStartValue) specifies the starting value of the uniform grid as GridStartValue.


collapse all

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

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

Extended Capabilities

Introduced in R2011a