Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- all variables in MATLAB are matrix
- >> x = 5
- x =
- 5
- >> size(x) % to know the lenght of the variable
- ans =
- 1 1
- >> v = [1 2 3]
- o % both are valid expression
- >> v = [1, 2, 3]
- >> size(v)
- ans =
- 1 3
- creating a matrix variable
- >> a = [1 2; 3 4]
- a =
- 1 2
- 3 4
- >> size(a)
- ans =
- 2 2
- ----------------
- you know that v = [1 2 3] which size was 1 3
- >> v = v'
- v =
- 1
- 2
- 3
- >> size(v)
- ans =
- 3 1
- ----
- access elements of the matrix
- example vector -> a = 1 2
- 3 4
- >> a(1,1)
- ans =
- 1
- >> a(1,2)
- ans =
- 2
- >> a(2,1)
- ans =
- 3
- -------------
- access a vector within a matrix
- example vector -> a = 1 2
- 3 4
- >> a(1,:)
- ans =
- 1 2
- >> a(:,2)
- ans =
- 2
- 4
- >> a(:,:)
- ans =
- 1 2
- 3 4
- ----------------------
- access a range in the matrix
- example vector -> x = 1 2 3 4
- 5 6 7 8
- 9 10 11 12
- 13 14 15 16
- >> x(2:3,2:3)
- ans =
- 06 07
- 10 11
- ----------------------
- the : syntax can create a range
- (create a row vector with the elements 1 to 10)
- >> w = 1:10
- w =
- 1 2 3 4 5 6 7 8 9 10
- >> size(w)
- ans =
- 1 10
Advertisement
Add Comment
Please, Sign In to add comment