1 / 16

Arrays

Arrays. CE 311 K - Introduction to Computer Methods Daene C. McKinney. Introduction. Arrays Two -Dimensional Arrays String Arrays & Splitting. Array. Index. 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. . . . . . . i. Arrays. A group of related things

anthea
Download Presentation

Arrays

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 CE 311 K - Introduction to Computer Methods Daene C. McKinney

  2. Introduction • Arrays • Two-Dimensional Arrays • String Arrays & Splitting

  3. Array Index 0 1 2 3 4 5 6 7 8 9 . . . . . . i Arrays • A group of related things • Sequentially indexed data structure (matrix) • All elements in an array have same data type • An element of an array is accessed using the array name and an index, e.g., A(i)

  4. Array Index 0 1 2 3 4 5 6 7 8 9 . . . . . . i Array Definition and Initialization • An array is defined using a declaration statement. Dim arrayName(0To end) As dataType • allocates memory for “end” elements • Index of first element is 0 • arrayName(0) is the first element • arrayName(end) is the last element

  5. Example Array w/ 5 elements Assign array values

  6. Flow Example - Revisited Array w/ 101 elements Assign array values Perform calculations using array Need the array values again for calculaitons

  7. Flow Example – Revised Again Pass Array to function “average” (see next slide) Pass Array to function “stdev” (see next slide)

  8. Flow Example - Revised Function to compute average Function to compute standard deviation

  9. 0 0 0 0 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 0 1 2 Multi-Dimensional Arrays A(0 To 4) A(0 To 4, 0 To 2) 0 1 2 3 4 A(0 To 4, 0 To 2, 0 To 2) A(2,2,2) – third row, third column, third layer

  10. Distances between Texas cities in km Example – 2D Arrays

  11. 2-D Array to Store Contents of Table Array Text file containing data Dim mile(0 To 3, 0 To 3) As Double Matrix containing data

  12. Example Declare array Load data into array before hitting the button Use data in array after entering origin and destination and hitting the button

  13. Flow Duration Curve Exceedence Probability

  14. Flow Duration Curve

  15. String Arrays & Splitting

  16. Summary • Arrays • Two-Dimensional Arrays • String Arrays & Splitting

More Related