Comments on: Logical indexing https://blogs.mathworks.com/steve/2017/03/07/logical-indexing-2/?s_tid=feedtopost Retired from MathWorks in 2024 after 30 years of service. Can now be found at MATLAB Central, https://hornjourney.com, and https://matrixvalues.com. MathWorks career included image processing, toolbox development, MATLAB development and design, development team management, MATLAB design standards, Steve on Image Processing blog (https://blogs.mathworks.com/steve). Co-author of Digital Image Processing Using MATLAB (https://www.imageprocessingplace.com/DIPUM-3E/dipum3e_main_page.htm). French horn enthusiast, member of Concord Orchestra and Melrose Symphony, member of the board of Cormont Music and the Kendall Betts Horn Camp. Fri, 01 Nov 2019 21:05:45 +0000 hourly 1 https://wordpress.org/?v=6.2.2 By: Dev-iL https://blogs.mathworks.com/steve/2017/03/07/logical-indexing-2/#comment-28445 Tue, 07 Mar 2017 22:15:21 +0000 https://blogs.mathworks.com/steve/?p=2511#comment-28445 Thanks again for the comment – it does help clear things up a bit!

]]>
By: Steve Eddins https://blogs.mathworks.com/steve/2017/03/07/logical-indexing-2/#comment-28444 Tue, 07 Mar 2017 21:52:23 +0000 https://blogs.mathworks.com/steve/?p=2511#comment-28444 Dev-iL—I can give a knowledgeable answer, but not an authoritative one. That is, I do know a lot about the history of MATLAB behavior, having been a developer at MathWorks since 1993, but I don’t work directly with the implementation code in this specific area. So, I can give you my own interpretation and educated guess about what has happened here.

In its commercial form, MATLAB has been around for 33 years now. Especially in its earliest days, MATLAB implementers had a tendency to be as permissive as possible with respect to input validation. Over time, we realized that this philosophy wasn’t always the best one for users, and we started making some of the language rules tighter and more regular. One example was the introduction of error messages about invalid indices (noninteger, nonpositive, etc.). However, we couldn’t always tighten up the behavior as much as we liked. Sometimes that was because we discovered that too much user code was exploiting the original behavior. That is one of the reasons you continue to see this kind of behavior variation in some places.

Generally, it is very unlikely that MathWorks developers will describe publicly the internal implementation details related to undocumented behavior, so I recommend against putting any effort into it. Instead, I would advise users to only use integer-valued indices. Users can explicitly call round or floor or whatever to convert the output of the colon operator to be integer-valued.

]]>
By: Dev-iL https://blogs.mathworks.com/steve/2017/03/07/logical-indexing-2/#comment-28443 Tue, 07 Mar 2017 21:31:35 +0000 https://blogs.mathworks.com/steve/?p=2511#comment-28443 Hello Steve,
While on the topic of indexing in MATLAB, I’d like to ask for your comment on the behavior, where MATLAB allows non-integer indices in some cases, as discussed in this post: http://stackoverflow.com/questions/40455299/ . This has caused much confusion to many of us on SO, and some official explanation could really help.
Thanks!

]]>