Programming |
Logical Indexing
A logical matrix provides a different type of array indexing in MATLAB. While most indices are numeric, indicating a certain row or column number, logical indices are positional. That is, it is the position of each 1 in the logical matrix that determines which array element is being referred to.
See Using Logicals in Array Indexing for more information on this subject.
Indexing on Assignment
When assigning values from one matrix to another matrix, you can use any of the styles of indexing covered in this section. Matrix assignment statements also have the following requirement.
In the assignment A(J,K,...) = B(M,N,...)
, subscripts J
, K
, M
, N
, etc. may be scalar, vector, or array, provided that all of the following are true:
B
, not including trailing subscripts equal to 1, does not exceed ndims
(B)
.
A
equals the number of nonscalar subscripts specified for B
. For example, A(5, 1:4, 1, 2) = B(5:8)
is valid because both sides of the equation use one nonscalar subscript.
A
matches the order and length of nonscalar subscripts specified for B
. For example, A(1:4, 3, 3:9) = B(5:8, 1:7)
is valid because both sides of the equation (ignoring the one scalar subscript 3
) use a 4-element subscript followed by a 7-element subscript.
Accessing Multiple Elements | Getting Information About a Matrix |
© 1994-2005 The MathWorks, Inc.