The Loc(), Loc Nonmissing(), Loc Min(), Loc Max(), and Loc Sorted() functions all return matrices that show positions of certain values in a matrix.
The Loc() function creates a matrix of positions that locate where A is true (nonzero and nonmissing).
A = [0 1 . 3 4 0];
B = [2 0 0 2 5 6];
The following example returns the indices for the values of A that are nonmissing and nonzero.
I = Loc( A );
The following example returns the indices for the values of A that are less than the corresponding values of B. Note that the two matrices must have the same number of rows and columns.
I = Loc( A < B );
A = [0 1 0 3 4 0];
Show( A );
The Loc Nonmissing() function returns a vector of row numbers in a matrix that do not contain any missing values. For example,
Loc Nonmissing( A );
The Loc Min() and Loc Max() functions return the position of the first occurrence of the minimum and maximum elements of a matrix. Elements of a matrix are numbered consecutively, starting in the first row, first column, and proceeding left to right.
The Loc Sorted() function is mainly used to identify the interval that a number lies within. The function returns the position of the highest value in A that is less than or equal to the value in B. The resulting vector contains an item for each element in B.
A = [10 20 30 40];
B = [35];
Loc Sorted( A, B );
A = [10 20 40];
B = [35 5 45 20];
Loc Sorted( A, B );
Here’s an example that defines a list of strings. Loc Sorted() identifies the string at the seventh interval and puts it in a list.
{"No Fat", "Some Fat", "Low Fat", "Normal Fat", "Medium Fat", "High Fat"}
{"No Fat", "Some Fat", "Low Fat", "Normal Fat", "Medium Fat", "High Fat"}
•
|
A must be sorted in ascending order.
|
•
|
The returned values are always 1 or greater. If the element in B is smaller than all of the elements in A, then the function returns a value of 1. If the element in B is greater than all of the elements in A, then the function returns n, where n is the number of elements in A.
|