# Matlab矩陣

``a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8]``

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

``````Trial>> a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8]

a =

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

## 引用矩陣中的元素

``mx(m, n);``

``````a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];
a(2,5)``````

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

``````Trial>> a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];
a(2,5)

ans =

6``````

``````a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];
v = a(:,4)``````

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

``````Trial>> a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];
v = a(:,4)

v =

4
5
6
7``````

``a(:,m:n)``

``````a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];
a(:, 2:3)``````

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

``````Trial>> a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];
a(:, 2:3)

ans =

2     3
3     4
4     5
5     6``````

``````a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];
a(:, 2:3)``````

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

``````Trial>> a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];
a(:, 2:3)

ans =

2     3
3     4
4     5
5     6``````

``````3     4     5
4     5     6``````

``````a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];
sa = a(2:3,2:4)``````

MATLAB執行上述語句，返回以下結果 -

``````sa =
3     4     5
4     5     6``````

## 刪除矩陣中的一行或一列

``````a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];
a( 4 , : ) = []``````

MATLAB執行上述語句，返回以下結果 -

``````a =
1     2     3     4     5
2     3     4     5     6
3     4     5     6     7``````

``````a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];
a(: , 5)=[]``````

MATLAB執行上述語句，返回以下結果 -

``````a =
1     2     3     4
2     3     4     5
3     4     5     6
4     5     6     7``````

``````a = [ 1 2 3 ; 4 5 6; 7 8 9];
new_mat = a([2,3,2,3],:)``````

``````new_mat =
4     5     6
7     8     9
4     5     6
7     8     9``````

• 矩陣的加法和減法
• 矩陣除法
• 矩陣的標量運算
• 矩陣的轉置
• 矩陣連接
• 矩陣乘法
• 矩陣的行列式
• 矩陣的逆轉