We all know the matlab colon operator to create a linear sequence, i.e.
1:5 = [1 2 3 4 5]
Now I found that the arguments of the colon operator can also be applied to vectors or matrices. However I do not understand the definition behind.
Examples
[1 2 3 4]:5 == [1 2 3 4 5]
[1 2; 3 4]:3 == [1 2 3]
Why is this?
The second argument can be vector or matrix as well.
Ultimately I would like to understand sequences such as
1:2:3:4:5
which is fully legal in matlab and [1 5]
by the way!
Note 1:2:3:4:5:6
is left associative i.e. parsed as ((1:2:3):4:5):6
.
So what is the behavior for the colon operator with matrix/vector arguments?
EDIT: corrected the statement of left associativity.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…