Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS320n –Visual Programming

Similar presentations


Presentation on theme: "CS320n –Visual Programming"— Presentation transcript:

1 CS320n –Visual Programming
Arrays

2 What We Will Do Today Learn about arrays and how to work with them in LabVIEW Visual Programming 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 Visual Programming 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 Visual Programming 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 Visual Programming 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 Visual Programming 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 Visual Programming 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. Visual Programming 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 Visual Programming 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 Visual Programming 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 Visual Programming 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 Visual Programming Arrays in LabVIEW

13 Using Auto indexing array indicator Visual Programming
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 Visual Programming Arrays in LabVIEW

15 Manipulating Arrays Many functions for working with arrays
initialize array initial value for all elements size of the array Visual Programming Arrays in LabVIEW

16 Getting the Length of an Array
output is size of array array input Visual Programming 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 value at element resulting array array array index new value for element Index Array index Replace Array Subset Visual Programming Arrays in LabVIEW

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

19 Class work Download the ArrayExercise.vi program from the class web site. The program creates an array of size 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 Visual Programming Arrays in LabVIEW


Download ppt "CS320n –Visual Programming"

Similar presentations


Ads by Google