# Matlab冒號符號

``````1:10
``````

MATLAB執行語句並返回一個包含整數的行向量，從`1``10` -

``````ans =

1    2    3    4    5    6    7    8    9   10
``````

``````100: -5: 50
``````

MATLAB執行語句並返回以下結果 -

``````ans =
100    95    90    85    80    75    70    65    60    55    50
``````

``````0:pi/8:pi
``````

MATLAB執行語句並返回以下結果 -

``````ans =
Columns 1 through 7
0    0.3927    0.7854    1.1781    1.5708    1.9635    2.3562
Columns 8 through 9
2.7489    3.1416
``````

`A(:,j)` `A`的第`j`
`A(i,:)` `A`的第`i`
`A(:,:)` 是等效的二維陣列。對於矩陣，這與`A`相同。
`A(j:k)` `A(j)`, `A(j+1)`,`...`,`A(k)`
`A(:,j:k)` `A(:,j)`, `A(:,j+1)`,`...`,`A(:,k)`
`A(:,:,k)` 是三維陣列`A`的第`k`
`A(i,j,k,:)` 是四維陣列`A`中的向量。向量包括`A(i，j，k，1)``A(i，j，k，2)``A(i，j，k，3)`等。
`A(:)` `A`的所有要素，被視為單列。在賦值語句的左側，`A(:)`填充`A`，從之前保留其形狀。在這種情況下，右側必須包含與`A`相同數量的元素。

## 範例

``````A = [1 2 3 4; 4 5 6 7; 7 8 9 10]
A(:,2)      % second column of A
A(:,2:3)    % second and third column of A
A(2:3,2:3)  % second and third rows and second and third columns
``````

``````A =
1     2     3     4
4     5     6     7
7     8     9    10

ans =
2
5
8

ans =
2     3
5     6
8     9

ans =
5     6
8     9
``````