-
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
-
Sort a list of complex numbers based on far they are from the origin.
5705 Solvers
-
Project Euler: Problem 10, Sum of Primes
1900 Solvers
-
Who has power to do everything in this world?
454 Solvers
-
393 Solvers
-
Find my daddy long leg (No 's')
2509 Solvers
More from this Author96
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!