120 likes | 292 Views
EGR115. Part1 – weeks 1 through 7. Part2 – Storing data. Arrays Files. Variables double / int char Equations MATLAB can skip if & switch MATLAB can repeat while & for. Part3 – Organizing lines of code. functions. Arrays – the Basics. Arrays Scalar Vectors Matrices.
E N D
EGR115 Part1 – weeks 1 through 7 Part2 – Storing data Arrays Files • Variables • double / int • char • Equations • MATLAB can skip if & switch • MATLAB can repeat while & for Part3 – Organizing lines of code • functions
Arrays – the Basics Arrays Scalar Vectors Matrices
1. An array • An array is a collection of data into one variable • The array has a more precise name, depending on the dimensions of the variable: • A “scalar” • A “vector” • A “matrix” • When talking about the dimension of any array, you will hear: “This array is a ___ by ____.” For example: • This array is a 3 by 4. 3 is the number of rows, 4 is the number of columns. The difference…
1st . “A scalar” • A single value. • This array is a 1 by 1. • Example: the number 7 is a scalar. age = 17; %creates a scalar variable weight = 145.32; %another scalar variable
2nd . “Vector” – math In 2D:
2nd . “Vector” – math In 2D: In 3D: The vector OP has initial point at the origin O(0,0,0) and terminal point at P(2,3,5). We can draw the vector OP as follows: Source: http://www.intmath.com/Vectors/1_Vector-concepts.php In 3D:
More than just math “Vector” – MATLAB • A vector is a one-dimensional collection of data • “all the temperatures readings during take-off” • “all the pressures recorded during Hurricane Katrina” • “an (x,y,z) coordinate” • A vector can only be of two types: a column, or a row • For an array to be a vector, only ONE of this variable's dimension is 1. A column vector (“m by 1”) A row vector (“1 by m”)
Vectors, end. • Vectors are usually thought of as “row vectors” or “column vectors”, but there exists one more: The “empty vector” – a variable in MATLAB that contains no values. To make an empty vector, use the empty brackets: array = []; • Why do this? • Create a variable, much like a container ready to accept values. • Erase the previous content of an array, without destroying the variable itself.
3rd . A “matrix” • Both dimensions are greater than 1. • Can be used to: • Represent mathematical matrices, or • Store related information • First row: temperature of different points in a nozzle • Second row: pressure at those same points • Third row: density at those same points an “r by c”
3rd . A “matrix”, vocabulary • LEARN this NOW – everything depends on you referring to these correctly! 1 2 3 4 5 6 7 8 9 0 3 1 5 6 1 4 3 5 6 7 3 1 2 0 0 ROW!
3rd . A “matrix”, vocabulary • LEARN this NOW – everything depends on you referring to these correctly! 1 2 3 4 5 6 7 8 9 0 3 1 5 6 1 4 3 5 6 7 3 1 2 0 0 COLUMN!
At this point in time… • Arrayscan only have 1 data-typeand 1 value per box. NUMERICAL CHAR MIX MULTIPLE VALUES per box