The meaning of colon operator in MATLAB

后端 未结 2 958
傲寒
傲寒 2020-11-29 14:04

I came across some MATLAB syntax with a colon that I don\'t fully understand.

First Question:

The expression: 0:pi/4:pi results in the answer

2条回答
  •  鱼传尺愫
    2020-11-29 14:27

    My two pennies to KennyTM's answer.

    Actually scalar and vector variables in MATLAB have 2 dimensions. Scalar has 1 row and 1 column, and vector has either 1 row or column. Just try size(X).

    Colon (:) operator for indexing simply means all. Syntax X(:,1:3) means get all rows and columns from 1 to 3. Since your variable X has only 1 row, you will get first 3 values in this row.

提交回复
热议问题