Main Content

val2ind

Uniform grid index

Description

example

indx = val2ind(val,delta) returns the index of the value val in a uniform grid with a spacing between elements of delta. The first element of the uniform grid is zero. If 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.

indx = val2ind(val,delta,startval) specifies the starting value of the uniform grid as startval.

Examples

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

Input Arguments

collapse all

Data values, specified as a scalar or vector.

Example: [3.4 6.3 9.8 12.1]

Data Types: double

Spacing between grid elements, specified as a positive scalar.

Example: 1/1e3

Data Types: double

Starting value of the uniform grid, specified as a scalar startval must be smaller than or equal to the minimum value in val.

Data Types: double

Extended Capabilities

Version History

Introduced in R2011a