The documentation for the colon operator says:
If you specify nonscalar arrays, MATLAB interprets j:i:k as j(1):i(1):k(1).
Your first example is interpreted as 1:3
, the second as 1:5
Expressions with more than two :
are parsed left-associative:
a:b:c:d:e==(a:b:c):d:e
.
>> 1:2:3:4:5
ans =
1 5