Does Matlab accept non-integer indices? Does Matlab accept non-integer indices? arrays arrays

Does Matlab accept non-integer indices?


Additional observations:

  • x(1.2:3) should theoretically be interpreted as: subsref(x, substruct('()',1.2:3)). However, as mentioned in the question, "No rounding takes place when the indexing array is a standard array", which causes the explicit subscripted reference to fail. This suggests that a mechanism similar to logical short-circuiting or perhaps multithreaded partitioning (where intermediate variable are "not really created") takes place.

  • The issued warning's identifier is MATLAB:colon:nonIntegerIndex.

Theories:

  • Perhaps there exist overloaded versions of the subscripted reference where there is an initial step of detecting whether the subscripts themselves are integers or not. In case they're not, MATLAB "redirects" this to some other family of classes (example).

Official comments:

  • This is what Steve Eddins of TMW had to say on the subject:

    ... 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. ... 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.