---
# System prepended metadata

title: MATLAB 2019/11/13

---

# MATLAB 2019/11/13

---

# 矩陣

#### A = [1 2; 3 4]
#### A*2 = [2 4; 6 8]
#### A^2 = [1 4; 9 16]
#### AI = inv(A) = [-2 1; 1.5 -0.5]

---

# #clean window清除視窗 clc

---

# 矩陣相乘 A^2 = [] * [] 

#### v = [3, 5, 9]
#### D = [0.8 1.2 3.7]
#### M = V.*D = [2.4 6.0 33.3]

---

# Random亂數
### rand -> 正數 / randn -> 正負數
### rand or rand() *1
### randn or randn() *1
### rand(x) or rand(x, y)
### randn(x) or randn(x, y)
#### ( x, y = 矩陣次方 )

### randi(imax, x, y) -> imax = 限制最大值, x, y 矩陣次方

---

# #省略符號「;」
#### 「;」分號: 省略顯示於commandLine

---

# Histogram 直方圖
#### U = rand(1, 10^5);
#### hist(U) -> 繪製直方圖

### 直方圖結果:
![](https://i.imgur.com/N3ZTtkI.png)

#### V = randi(50, 2, 3)

---

### #清除Workspace記憶體暫存 clear

---

### #Current Folder => 當前路徑

---

#### C1 = randi(100, 100, 5);
#### A = C1(3, 5)
#### A = C1([2 3 4], [4 5 6])
#### A = C1([2:4], [4:6])

---

# Excel 檔案讀寫

## #寫入 xlswrite(filename, A, sheet, xlRange)
### filename 檔名
### A 儲存之數值
### sheet 表格
### xlRange 範圍
### xlswrite('d1.xlsx', C1, 'data')

## #讀取 xlsread(filename, sheet, xlRange, mode)
### xlsread('d1.xlsx', 'data', 'A1:E5', 'basic')
### :information_source: 無法正確讀取: mode => 'basic'

---

# 自動生成特定矩陣
### mask = zeros(1, 10) => 0 0 0 0 0 0 0 0 0 0
### mask = ones(1, 10)  => 1 1 1 1 1 1 1 1 1 1

---

# 公差數列
## S1 = 0:3:14 (起始數值:公差:最大數值)
### mask(4:7) --------------> 1 1 1 1 1 1 1 1 1 1
### mask(4:7) = 0 ----------> 1 1 1 0 0 0 0 1 1 1
### mask(4:7) = [3 5 8 9] --> 1 1 1 3 5 8 9 1 1 1

### mask(4:7) = 0 ----------> 1 1 1 0 0 0 0 1 1 1
### I = randi(50, 1, 10) ---> 18 20 23 3 27 41 1 33 5 29 
### IO = I.*mask -----------> 18 20 23 0 0 0 0 33 5 29

---