matlab4 - Matlab Arrays Vectors Initialize vectors either...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Matlab Arrays
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Vectors Initialize vectors either like : V = [1 2 3 4 5], or : V = [1,2,3,4,5] In order to create a column vector : V = [1;2;3;4;5] You can put any numeric expression for the individual elements of your vector
Background image of page 2
Accessing Vector Elements Given v = [1 2 3 4 5], or v = [1;2;3;4;5] V(1) returns 1, V(2) 2, … v(5) 5 v(6) ??? Index exceeds matrix dimensions. v(0) ??? Subscript indices must either be real positive integers or logicals.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Changing Vector Elements >> v(3) = 8 v = 1 2 8 4 5 >> v(0) = 0 ??? Subscript indices must either be real positive integers or logicals. >> v(7) = 128 v = 1 2 8 4 5 0 128
Background image of page 4
Strings are also vectors … >> st = 'abcde' st =abcde >> st(0) ??? Subscript indices must either be real positive integers or logicals. >> st(3) ans =c >> st(3) = 'X' st =abXde >> st(10) = 'O' st =abXde O
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Transpose Operator >> [1 2 3]' ans = 1 2 3 >> [1;2;3]' ans = 1 2 3
Background image of page 6
Vector length >> length(v) ans = 7 >> length(v') ans = 7 >> v(length(v)) ans = 128 >> v(end) ans = 128
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 19

matlab4 - Matlab Arrays Vectors Initialize vectors either...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online