# matlab4 - Matlab Arrays Vectors Initialize vectors either...

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

Matlab Arrays

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

View Full Document
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
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.

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

View Full Document
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
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

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

View Full Document
Transpose Operator >> [1 2 3]' ans = 1 2 3 >> [1;2;3]' ans = 1 2 3
Vector length >> length(v) ans = 7 >> length(v') ans = 7 >> v(length(v)) ans = 128 >> v(end) ans = 128

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 10/29/2010 for the course CS 111 taught by Professor Stuff during the Fall '08 term at Bilkent University.

### 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
Ask a homework question - tutors are online