| Using the C++ Math Library | ![]() |
Using a Scalar and a Logical Vector
Let matrix X be a 4-by-4 magic square.
X = magic(4); 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
Let B be a logical matrix that indicates which elements in row 2 of matrix X are greater than 9. B is the result of the greater than (>) operation
B = X(2, colon()) > 9;
0 1 1 0
Use B as a logical index that selects those elements from matrix X.
X(2,B)
11 10
| Using One colon() Index and One Logical Vector as Indices | Extending Logical Indexing to N Dimensions | ![]() |