Lecture 3

# Lecture 3 - Lecture 3 Arrays BMEn 2401 Programming for...

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

9/21/2010 1 Lecture 3: Arrays BMEn 2401 Programming for Biomedical Engineers Rich Beck September 21, 2010 1 Vector and Matrices So far you learned scalar variables: radius_of_sphere = 2.67; You need to handle certain data types with Vectors (one-dimensional arrays) Matrices (two-dimensional arrays) Example: Position of point P is defined by a vector (1, 1.5, 4 ) x y z P 1 4 1.5 2

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

View Full Document
9/21/2010 2 Student ID HW Grade 3257689 98 3257452 100 3257324 93 3257267 95 3257449 100 3257335 97 Student_ID_vector HW_Grade_vector 3 To separate data you can use comma or space Creating Vectors in MATLAB vector_name = [ values ] Examples: Position_of_P = [1, 1.5, 4] HW_Grade_vector = [ 98 100 93 95 100 97 ] 4
9/21/2010 3 Creating Vectors Using “:” vector_name =[first_element:spacing:last_element] Example: vector1 = [ -1:3:29 ] vector1 = -1 2 5 8 11 14 17 20 23 26 29 If spacing is omitted the default value is 1: vector2 = [ 2:9 ] vector2 = 2 3 4 5 6 7 8 9 Square brackets are optional. 5 Test Yourself Using “:” write a code which creates the following vectors: V1 = 1.0800 1.0900 1.1000 1.1100 1.1200 V2 = 5 3 1 -1 6

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

View Full Document
9/21/2010 4 Creating Vectors Using linspace command vector_name = linspace (f_ele ,l_ele , n ) Example: Vector_var = linspace ( 0 , 1.6 , 9 ) Vector_var = 0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 When number of elements is omitted the default is 100 First element last element Total number of elements 7 Test yourself Use linspace command to create the following vectors: V1 = [ 10 20 30 40 50 60 ] V2 = [-2.8 -2.16 -1.52 -0.88 -0.24 0.4] 8
9/21/2010 5 Creating Matrices vector_name = [ values ] Matrix_name = [ values ; values ; values ] semicolons are necessary to separate the row. Example :

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.

{[ snackBarMessage ]}

### Page1 / 19

Lecture 3 - Lecture 3 Arrays BMEn 2401 Programming for...

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

View Full Document
Ask a homework question - tutors are online