1 / 16

Arrays – the Basics

Arrays – the Basics. Arrays Scalar Vectors Matrices. 1. 1. An array. An array is a collection of data into one variable The array has a more precise name , depending on the dimension of the variable: A “scalar” A “vector” A “matrix”. The difference…. 2. 1 st . “A scalar ”.

thuyet
Download Presentation

Arrays – the Basics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Arrays – the Basics Arrays Scalar Vectors Matrices 1

  2. 1. An array • An array is a collection of data into one variable • The array has a more precise name, depending on the dimension of the variable: • A “scalar” • A “vector” • A “matrix” The difference… 2

  3. 1st . “A scalar” • A value, just one. • The dimension is 1 x 1. • Example: the number 7 is a scalar. age = 17; %creates a scalar variable weight = 145.32; %another scalar variable 3

  4. 2nd . “Vector” – math In 2D: 4

  5. 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: 5

  6. “Vector” – Matlab • A vector is only a collection of data • “all the temperatures readings during take-off” • “all the pressures recorded during Hurricane Katrina” • “an (x,y,z) coordinate” 6

  7. “Vector” – Matlab • A vector is only a 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”) 7

  8. Vectors, end. • Vectors are usually thought of as “row vectors” or “column vector”, 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: E = [];

  9. Vectors, end. • Vectors are usually thought of as “row vectors” or “column vector”, 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: E = []; • 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.

  10. 3rd . A “matrix” • Both dimensions are greater than 1. • Can be used to: • Represent mathematical matrices, or • Simply store 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” 10

  11. 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!

  12. 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!

  13. Wrapping Up • Vocabulary: array, scalar, vector, matrix, row, column 13

  14. Wrapping Up • Vocabulary: array, scalar, vector, matrix, row, column • An array allows a LOT of data to be stored into ONE variable. • Useful since when there is a LOT of data, having a separate variable for each number would be insane to keep track of! 14

  15. Wrapping Up • Vocabulary: array, scalar, vector, matrix, row, column • An array allows a LOT of data to be stored into ONE variable. • Useful since when there is a LOT of data, having a separate variable for each number would be insane to keep track of! • There are different types of arrays: scalars, vectors and matrices. • Each specific name is linked to the dimension of the variable. 15

  16. Wrapping Up • Vocabulary: array, scalar, vector, matrix, row, column • An array allows a LOT of data to be stored into ONE variable. • Useful since when there is a LOT of data, having a separate variable for each number would be insane to keep track of! • There are different types of arrays: scalars, vectors and matrices. • Each specific name is linked to the dimension of the variable. • Reset any array to empty using a set of empty square brackets. 16

More Related