| Using the C++ Math Library | ![]() |
Using a Logical Matrix As a One-Dimensional Index
When you use a logical matrix as an index, the result is a column vector. For example, you can create the logical index matrix B:
1 0 1 0 1 0 1 0 1
mwArray B = logical(vertcat(horzcat(1,0,1), horzcat(0,1,0), horzcat(1,0,1)));
1 3 5 7 9
Notice that B has ones at the corners and in the center, and that the result is a column vector of the corner and center elements of A.
If the logical index is not the same size as the subscripted array, the logical index is treated like a vector. For example, if B = [1 0; 0 1] then A(B) equals
1 4
since B has a zero at positions 2 and 3, and a 1 at positions 1 and 4. Logical indices behave just like regular indices in this regard.
| Overview | Using Two Logical Vectors as Indices | ![]() |