The LOGICAL function documentation, accessible by typing the following at the MATLAB prompt:
web([docroot,'/techdoc/ref/logical.html'])
states the following:
A(B), where B is a logical array, returns the values of A at the indices where the real part of B is nonzero. B must be the same size as A.
This implies that if B does not have the same size as matrix A, the logical indexing will return an error. However, if I index matrix A with a logical indexing matrix B whose size is smaller than matrix A as follows:
A = [1 2 3; 4 5 6; 7 8 9];B = [ 0 1 0; 1 0 1];A(logical(B))
MATLAB returns the following output instead of returning an error:
ans = 4 7 8
Best Answer