behavior of colon operator (:) with matrix or vector arguments

后端 未结 1 1786
星月不相逢
星月不相逢 2020-12-11 01:17

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 oper

相关标签:
1条回答
  • 2020-12-11 01:42

    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
    
    0 讨论(0)
提交回复
热议问题