1 / 19

CS320n –Visual Programming

CS320n –Visual Programming. Arrays. What We Will Do Today. Learn about arrays and how to work with them in LabVIEW. What are Arrays?. An array is like a list Up until now in LabVIEW we have dealt with scalars , variables with a single value An array is a collection of elements

tgeorge
Download Presentation

CS320n –Visual Programming

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. CS320n –Visual Programming Arrays

  2. What We Will Do Today • Learn about arrays and how to work with them in LabVIEW Arrays in LabVIEW

  3. What are Arrays? • An array is like a list • Up until now in LabVIEW we have dealt with scalars, variables with a single value • An array is a collection of elements • all elements in the array have the same data type: boolean, double, int, String Arrays in LabVIEW

  4. Thinking About Arrays • Array elements are accessed by their index • Indices start at 0, not 1 • This is a one dimensional array • arrays can have more dimensions • 2 dimensional array, like a table of data Index 0 1 2 3 4 5 6 7 Element 2.3 1.7 3.9 0.2 -1.7 4.5 1.66 3.1 Arrays in LabVIEW

  5. Arrays in LabVIEW • Arrays can be created on the block diagram • on block diagram select arrays sub palette • select array constant and drag onto block diagram • this creates an array shell Arrays in LabVIEW

  6. Creating an Array on Block Diagram array shell • to finish creating the array the data type the array holds must be determined • drag a constant from a sub palette into the elements portion • this determines the data type of the array index elements after dragging numeric constant into elements Arrays in LabVIEW

  7. Array Constants on Block Diagram • type the initial value into the element section • the array can be expanded up and down or left and right to view other elements • click and drag to expand array to view more elements element 0 set to 12 Arrays in LabVIEW

  8. Array Constants on Block Diagram Array expanded to show elements 0 through 10 Clicking on index array display other elements. The element on the far left (or top) of the array has the index shown in the index box. Light blue elements are elements that have not been initialized. Arrays in LabVIEW

  9. Creating Arrays Via the Front Panel • Arrays can also be created via the front panel • click on the Array and Cluster sub palette • click and drag an array to the front panel • this creates an array control shell Arrays in LabVIEW

  10. Creating Arrays Via the Front Panel • a data type must be added to the array shell • drag a control or indicator of the data type you want into the shell • can change from double to int by right clicking on elements and selecting “data range” • click on icon under “representation” and change to an integer type array shell Arrays in LabVIEW

  11. Arrays on the Front Panel • Control can be expanded to show more elements of the array • grey elements indicate uninitialized values • the size (or length) of the array above is 1 • if other elements are given values, the array size automatically expands Arrays in LabVIEW

  12. Auto indexing • LabVIEW has a feature with loops and arrays called auto indexing • If you wish to carry out an operation on every element of an array a loop is required • assume we have an array and we want to double every element Arrays in LabVIEW

  13. Using Auto indexing array indicator Arrays in LabVIEW

  14. Notes on Previous slide • no value wired to count terminal • count based on length of array • thick wire going in and coming out, but thin inside the loop • working with a single element of the array • must create array indicator to show array when finished • can be a bit tricky Arrays in LabVIEW

  15. Manipulating Arrays • Many functions for working with arrays • initialize array initial valuefor all elements size of the array Arrays in LabVIEW

  16. Getting the Length of an Array output is size of array array input Arrays in LabVIEW

  17. Changing Values of Elements • Giving an array, set the value at position 2 (actually the 3rd element of the array) to 1 more than its previous value • Uses Index Array and Replace Array Subset resultingarray value at element array array index new value forelement Index Array index Replace ArraySubset Arrays in LabVIEW

  18. Completed Diagram Index Array (access element) Replace Array Subset(Change value of 1 element) Arrays in LabVIEW

  19. Class work • Download the ArrayExercise.vi program from the class web site. • The program creates an array of size 1000. The elements of the array are random values from 1 to 100 • Add 1 to all elements that are odd. • Use a case statement or select function inside the loop to increment the array element if R is equal to 1 Arrays in LabVIEW

More Related