Can I perform logical indexing when the logical indexing matrix is smaller then the indexed matrix in MATLAB 7.0 (R14)?
2 views (last 30 days)
Show older comments
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
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
This is an error in the documentation for the LOGICAL function in MATLAB 7.0 (R14). The documentation should read as follows:
When the logical indexing matrix is smaller than the indexed matrix, MATLAB expands the logical indexing matrix with false (or zero) values to be of the same size as the indexed matrix.
0 Comments
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!