MATLAB 02-2 (Array)

신예진·2022년 1월 25일
0

Matlab Simulink

목록 보기
3/17

1) how to make arrays

use []
, or space % to add element to the right
; % to add element to the next row

2) Ex

a = [1 2 3]
b = [1 2 3; 4 5 6]

3) colon operator (can omit [])

x = 1:6
x = 1 : pi/50 : pi % first : stepsize : last
x = 0 : -2 : -5

4) linspace

linspace(first,last,number)
linspace(0,7,10)

5) transpose

c = b'

6) functions for generating large array

b1 = 1:0.1:2
b2 = rand(5,4)
b3 = ones(3,4)
b4 = zeros(8,3)
b5 = eye(3) % identity matrix

7) row vector (1D array)

rand(1,4)

8) column vector (1D array)

rand(5,1)

9) matrix (2D array)

rand(5,3)

10) ":" gives row vector

1:4 % (1x4)
[1:4]' % (4x1)

11) +,-,*,^ works for matrices

< dimension을 잘 살펴볼 것! >

A = rand(4,3) 
B = rand(4,3)
C = rand(3,3)
A + B
A * B'
A' * B
C^3 %same as C*C*C

12) elementwise operation (vectorization)

A .* B
A ./ B
A .^ B

13) combining matrices ⟹ same rule as "how to make arrays"

[], comma or space, semicolon
D = [A', C ; rand(3,3) B'] % D는 (6x7)

0개의 댓글