-
5 Comments
It is odd that matlab distinguishes between logical 1's and number 1's yet 1 and logical 1 are considered equal.
isequal([0 1],[false true])=1, yet if a is [1 2], a([0 1]) returns an error instead of 2, as it does with a([false true]).
@Brandon This appears to be an inconsistency, but it isn't really. true and false (more or specifically, the logical values 0 and 1) are equal to (in the sense of isequal) but distinguishable from the numerical (double) values 0 and 1. (And the concepts of equality and distinguishability are themselves distinct.)
Furthermore, MATLAB generally emphasizes usefulness to the user, and logical indexing is obviously very useful.
I didn't know I could not use the word "else" in the code until I submitted and passed all but the first of 8 tests. Also, I was not sure if they wanted the output to be a string ("true" or "false") or if 0 and 1 was sufficient.
Suggested Problems
-
1648 Solvers
-
739 Solvers
-
Is this is a Tic Tac Toe X Win?
513 Solvers
-
978 Solvers
-
2161 Solvers
More from this Author96
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!