arrays - delhi universitybcas.du.ac.in/wp-content/uploads/2020/04/b.sch...that will make program...

43
Arrays A group of homogeneous elements of a specific data type is known as an array. It is one of the simplest data structures. Arrays hold a sequence of data elements of same data type placed in contiguous memory locations that can be individually referenced. So if you have many values, lets say we have to find average of marks of 1000 students. Now you will have to use 1000 variable names to store 1000 marks. That will make program lengthy, difficult to write and comprehend. Instead if you have array marks[], then you can store marks of 1000 students with same name marks. Hence arrays are essentially a way to store many values under the same variable name. Now question arises how to access individual marks of students? The answer is simple. Individual elements in the array are accessed by their position in the array. The position is given by an index, which is also called a subscript. The index usually uses a consecutive range of integers.

Upload: others

Post on 18-Aug-2021

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

Arrays• A group of homogeneous elements of a specific data type is known as an array.

• It is one of the simplest data structures.

• Arrays hold a sequence of data elements of same data type placed in contiguous memory locationsthat can be individually referenced.

• So if you have many values, lets say we have to find average of marks of 1000 students. Now you willhave to use 1000 variable names to store 1000 marks. That will make program lengthy, difficult to writeand comprehend.

• Instead if you have array marks[], then you can store marks of 1000 students with same name marks.Hence arrays are essentially a way to store many values under the same variable name.

• Now question arises how to access individual marks of students? The answer is simple. Individualelements in the array are accessed by their position in the array.

• The position is given by an index, which is also called a subscript. The index usually uses a consecutiverange of integers.

Page 2: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

• So we can say when we have collection of similar data or when we have to do repetitive computations, we can use arrays.

• Infact, arrays are ideal for storing data you collect from waveforms, graphs, data generated in loops or data collected from multiple sensors. All these are collection of similar data.

• Arrays can be one, two or multi-dimensional. We will restrict ourselves to one or two dimensional arrays only in this course.

How to use arrays in LabVIEW?• In LabVIEW, arrays used are similar to those used in textual conventional languages.

• An array consists of elements and dimensions.

• Elements are the data that make up an array. A dimension is the length, height or depth of an array e.g2 X 2 means an array with two rows and two columns.

• An array can have one or more dimensions and as many as (231) – 1 elements per dimension as permitted by memory of the system.

Page 3: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

• All elements in an array are ordered. So to locate a particular element in an array you need to know one index per dimension. For example, if you want to locate a particular element in a two-dimensional array, you need both row index and column index.

• In LabVIEW, indexes let us navigate through an array and retrieve elements, rows and columns from an array on the block diagram.

• The index starts from 0 to n-1, where n is the number of elements in the array with the first element at index 0 and the last one at index (n – 1).

• For example, if you create an array of 10 elements, the index ranges from 0 to 9. The fourth element has an index of 3.

• You can build arrays of numeric, Boolean, path, string and cluster data types

• BUT You cannot create arrays of arrays.

• However, you can use a multidimensional array or an array of clusters where each cluster contains one or more arrays. It will be more clear to you when we discuss clusters

• Also, you cannot create an array of subpanel controls, tab controls, .NET controls, ActiveX controls, charts or multiplot XY graphs

Page 4: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

Creating Array Controls and Indicators• To create an array in LabVIEW, you must place an array shell on the front panel and then place an element, such as a numeric,

Boolean, or waveform control or indicator, inside the array shell.

• Create a new VI.

• Right-click on the front panel to display the Controls palette.

• On the Controls palette, navigate to Modern»Array, Matrix, & Cluster and drag the Array shell onto the front panel.

Page 5: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

4. On the Controls palette, navigate to Modern»Numeric and drag and drop a numeric indicator inside the Array shell.

5. Place your mouse over the array and drag the right side of the array to expand it and display multiple elements

Page 6: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

• The previous steps walked you through creating a 1D array.

• A 2D array stores elements in a grid or matrix. Each element in a 2D array has two corresponding index values, a row index and a column index. Again, as with a 1D array, the row and column indices of a 2D array are zero-based i.e start from 0 to n-1.

• To create a 2D array, you must first create a 1D array and then add a dimension to it. Return to the 1D array you created earlier.

1. On the front panel, right-click the index display and select Add Dimension from the shortcut menu.

Page 7: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

2. Place your mouse over the array and drag the corner of the array to expand it and display multiple rows and columns.

Up to this point, the numeric elements of the arrays you have created have been dimmed zeros. A dimmed array element indicates that the element is uninitialized. To initialize an element, click inside the element and replace the dimmed 0 with a number of your choice.

Page 8: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

• You can initialize elements to whatever value you choose.

Creating Array Constants

1. You can use array constants to store constant data or as a basis for comparison with another array. On the block diagram, right-click to display the Functions palette.

2. On the Functions palette, navigate to Programming»Array and drag the Array Constant onto the block diagram.

Page 9: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

3. On the Functions palette, navigate to Programming»Numeric and drag and drop the Numeric Constant inside the Array Constant shell.

4. Resize the array constant and initialize a few of the elements.

Page 10: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

Array Inputs/Outputs

• If you wire an array as an input to a for loop, LabVIEW provides the option to automatically set the count terminal of the for loop to the size of the array using the Auto-Indexing feature. You can enable or disable the Auto-Indexing option by right-clicking the loop tunnel wired to the array and selecting Enable Indexing (Disable Indexing).

So what is autoindexing?

• If you wire an array to a For Loop or While Loop input tunnel, you can read and process every element in that array by enabling auto-indexing.

• When you auto-index an array output tunnel, the output array receives a new element from every iteration of the loop.

Autoindexing enabledAutoindexing disabled

Page 11: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

• Disable auto-indexing if you need only the last value passed to the tunnel.

• Auto-indexing is enabled by default for every array you wire to a For Loop and for each output tunnel that is created. For whileloops autoindexing is disabled by default.

USING AUTO-INDEXING TO SET THE FOR LOOP COUNT

• If you enable auto-indexing on an array wired to a For Loop input terminal, LabVIEW sets the count terminal to the array size so you do not need to wire the count terminal. E.g in fig below the for loop executes equal to the number of elements in the array.

• Normally, if the count terminal of the For Loop is not wired, the run arrow is broken. However, in this case the run arrow is not broken

Page 12: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

• If you enable auto-indexing for more than one tunnel as shown in Figure or if you wire the count terminal, the

count changes to the smaller of the two.

Page 13: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

1. Create a new VI. Navigate to File»New VI.

2. Create and initialize two 1D array constants, containing six numeric elements, on the block diagram similar to the array constants shown below.

Page 14: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

3. Create a 1D array of numeric indicators on the front panel. Change the numeric type to a 32-bit integer. Right-click on the array and select Representation»I32.

4. Create a for loop on the block diagram and place an add function inside the for loop.5. Wire one of the array constants into the for loop and connect it to the x terminal of the add function.

Page 15: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

6. Wire the other array constant into the for loop and connect it to the y terminal of the add function.

7. Wire the output terminal of the add function outside the for loop and connect it to the input terminal of the array of numeric indicators.

Page 16: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

8. Your final block diagram and front panel should be similar to those shown below.

Page 17: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

9. Go to the front panel and run the VI. Note that each element in the array of numeric indicators is populated with the sum of the corresponding elements in the two array constants.

Be aware that if you enable Auto-Indexing on more than one loop tunnel and wire the for loop count terminal, the number of iterations is equal to the smaller of the choices. For example, in the figure below, the for loop count terminal is set to run 15 iterations, Array 1 contains 10 elements, and Array 2 contains 20 elements. If you run the VI in the figure below, the for loop executes 10 times and Array Result contains 10 elements. Try this and see it for yourself.

Page 18: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

CREATING TWO-DIMENSIONAL ARRAYS USING LOOPS

You can create a 2D array using nested for loops and Auto-Indexing as shown below. The outer for loop creates the row elements, and the inner for loop creates the column elements.

Page 19: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

• POLYMORPHISM

• All LabVIEW arithmetic functions are polymorphic.

• This means that the inputs to these functions can be different data structures such as scalar values and arrays.

• Polymorphism is the ability of a numeric function to adjust to input data of different data structures.

• For example, the Add function can be used in the following ways.

• 1. Scalar + Scalar = Scalar addition.

• 2. Scalar + Array = The scalar is added to each element of array.

• 3. Array + Array = Each element of one array is added to the corresponding element of other array.

Page 20: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

Adding two arrays of same size

Adding two arrays of different size

Page 21: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

CLUSTERS• Clusters group data elements of mixed types. An example of a cluster is the LabVIEW error cluster, which combines a Boolean

value, a numeric value, and a string.

• A cluster is similar to a record or a struct in text-based programming languages.

• Similar to arrays, a cluster is either a control or an indicator and cannot contain a mixture of controls and indicators. The difference between clusters and arrays is that a particular cluster has a fixed size, where a particular array can vary in size. Also, a cluster can contain mixed data types, but an array can contain only one data type.

Advantages of using Clusters

• Bundling several data elements into clusters eliminates wire clutter on the block diagram.

• It also reduces the number of connector pane terminals that subVIs need by passing several values to one terminal. The connector pane has, at most, 28 terminals. If your front panel contains more than 28 controls and indicators that you want to pass to another VI, group some of them into a cluster and assign the cluster to a terminal on the connector pane.

Page 22: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

• In Figure (a) below, individual values are passed to the connector pane terminals. In Figure (b) controls and indicators are grouped into clusters and connected to one control panel terminal each.

Page 23: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

Creating Clusters1. Create a new VI.

2. Right-click on the front panel to display the Controls palette.

3. On the Controls palette, navigate to Modern»Array, Matrix, & Cluster and drag the Cluster shell onto the front

panel.

Page 24: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

4. Resize the Cluster shell so that it is big enough to contain multiple elements.

5. On the Controls palette, navigate to Modern»Numeric and drag and drop a numeric control inside the Cluster shell.

Page 25: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

6. On the Controls palette, navigate to Modern»String & Path and drag and drop a String Control inside the Cluster shell.

7. On the Controls palette, navigate to Modern»Boolean and drag and drop a Vertical Toggle Switch inside the Cluster shell.

Page 26: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

8.Your cluster should now look similar to the one shown below

You can now wire the numeric, string, and Boolean controls throughout the block diagram with one wire rather than

three separate wires.

Page 27: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

Creating Cluster Constants

• Similar to array constants, you can use cluster constants to store constant data or as a basis for comparison with another cluster. Create cluster constants the same way you created array constants in the steps discussed earlier.

If you already have a cluster control or indicator and want to make a cluster constant that contains the same data types, make a

copy of the cluster control or indicator on the block diagram and then right-click on the copy and select Change to Constant from

the shortcut menu.

Page 28: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

Cluster Functions

• We will be discussing four main cluster functions often used to manipulate clusters. These are the Bundle, Unbundle, Bundle ByName, and Unbundle By Name functions.

Use the Bundle function to assemble a cluster from individual elements. You also can use this function to change the values of

individual elements in an existing cluster without having to specify new values for all elementsTo wire elements into the Bundle function, use your mouse to resize the function or right-click on the function and select Add

Input from the shortcut menu.

Page 29: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],
Page 30: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

Bundle By Name

• The Bundle By Name function is used to replace one or more elements in an existing cluster.

• This function refers to cluster elements by name instead of by their position in the cluster.

• After you wire the node to an input cluster, right-click the name terminals to select elements from the shortcut menu.

• All inputs are required.

• The connector pane displays the default data types for this polymorphic function.

• Figure below shows a Bundle By Name function used to modify the values of an existing input cluster which contains a string control and a numeric control.

• The new value for both the elements must be given, otherwise LabVIEW shows an error.

Page 31: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

• The Bundle By Name function is very useful when modifying existing clusters because it lets you know exactly which cluster element you are modifying. For example, consider a cluster that contains two string elements labeled “String 1” and “String 2.” If you use the Bundle function to modify the cluster, the function terminals appear in the form of pink abc’s. You do not know which terminal modifies “String 1” and which terminal modifies “String 2.”

However, if you use the Bundle By Name function to modify the cluster, the function terminals display the element label so that you know which terminal modifies “String 1” and which terminal modifies “String 2.”

Page 32: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

Use the Unbundle function to disassemble a cluster into its individual elements.

Use the Unbundle by Name function to return specific cluster elements you specify by name.

You can also resize these functions for multiple elements in the same manner as the Bundle and Bundle By Name functions.

Page 33: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

Cluster Order

• Cluster elements have a logical order unrelated to their position in the shell. The first object you place in the clusteris element 0, the second is element 1, and so on. If you delete an element, the order adjusts automatically. Thecluster order determines the order in which the elements appear as terminals onthe Bundle and Unbundle functions on the block diagram. You can view and modify the cluster order by right-clicking the cluster border and selecting Reorder Controls In Cluster from the shortcut menu.

The white box on each element shows its current place in the cluster order. The black box shows the element’s new

place in the order. To set the order of a cluster element, enter the new order number in the Click to set to text box

and click the element. The cluster order of the element changes, and the cluster order of other elements

automatically adjusts. Save the changes by clicking the Confirm button on the toolbar. Revert to the original order by

clicking the Cancel button.

Page 34: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

Why is cluster order important?

• To wire clusters to each other, both clusters must have the same number of elements.

• Corresponding elements, determined by the cluster order, must have compatible data types.

ERROR CLUSTER

• Error clusters tell you why and where errors occur.

• When you perform any kind of I/O, there will possibility that errors will occur.

• Almost all I/O functions return error information i.e either they will return a numeric code or error cluster.

• Include error checking in VIs, especially for I/O operations such as file, serial, instrumentation, data acquisition, and communication operations, and provide a mechanism to handle errors appropriately.

• Without a mechanism to check for errors, you know only that the VI does not work properly.

• Checking for errors in VIs can help you identify the following problems:

1. You initialized communications incorrectly or wrote improper data to an external device.

2. An external device lost power, is broken, or is not working properly.

3. You upgraded the operating system software which changed the path to a file or the functionality of a VI or library. You might notice a problem in a VI or a system program.

Page 35: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

• The error clusters include the following components of information

status is a Boolean value that reports True if an error occurred. For example, you can wire an error cluster to the Boolean inputs

of the Stop, Quit LabVIEW, or Select functions. If an error occurs, the error cluster passes a True value to the function and you

may be able to stop or quit labview or select any other task. So it helps a programmer to choose error handling measures unlike

conventional languages where there was only one way i.e stopping the execution and highlighting that there is an error

code is a 32-bit signed integer that identifies the error numerically. A non-zero error code coupled with a status of False signals a

warning rather than a fatal error.

● source is a string that identifies where the error occurred. Use the error cluster controls and indicators to create error inputs and

outputs in subVIs.

When an error occurs, right-click within the cluster border and select Explain Error from the shortcut menu to open the Explain

Error dialog box. The Explain Error dialog box contains information about the error. The shortcut menu includes an Explain

Warning option if the VI contains warnings but no errors.

Page 36: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

Error Handling in LabVIEW

• Error handling in LabVIEW follows the data flow model. Just as data flow through a VI, so can error information.

• Wire the error information from the beginning of the VI to the end. Include an error handler VI at the end of the VI to determine if the VI ran without errors.

• Use the error in and error out clusters in each VI you use or build to pass error information through the VI

• As the VI runs, LabVIEW tests for errors at each execution node.

• If LabVIEW does not find any errors, the node executes normally.

• If LabVIEW detects an error, the node passes the error to the next node without executing. The next node does the same thing and so on. At last if there is error one can use error handler VI to decide what to do?

• See by default if any error occurs when a VI runs then LabVIEW handles it by suspending execution, highlighting the subVI or function where the error occurred, and displaying a dialog box.

• But in LabVIEW a programmer can choose other error handling methods also.

• For example, if an I/O VI (I/O VI is VI dealing with input output operations e.g aquiring data from sensors, printing characters on the attached printer etc.) on the block diagram times out, you might not want the entire application to stop.

• You also might want the VI to retry for a certain period of time.

• In LabVIEW, we can make these error handling decisions on the block diagram of the VI by using error clusters in each VI and then using error handler VI to decide the next action if error occurs.

Page 37: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

PLOTTING DATA

• Graphical display of data is an important aspect of programming in LabVIEW

• VIs with graph usually collects the data in an array and then plots the data to the graph to obtain a waveform.

• Two-dimensional X-Y displays are required in most situations whereas Charts and graphs let you display plots of data in a graphical form.

• Charts interactively plot data, appending new data to old so that you can see the current value in the context of previous data, as the new data become available.

• Graphs on the other hand plot pre-generated arrays of values in a more traditional fashion without retaining previously-generated data

• Although LabVIEW includes the following types of graphs and charts:

Waveform graphs and charts, XY Graphs, Intensity graphs and charts, Digital waveform graphs, Windows 3D Graphs.

We will be covering waveform graphs and charts and XY plots in our course

Page 38: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

WAVEFORM GRAPHS

• The waveform graph displays one or more plots of evenly sampled measurements.

• The waveform graph plots only single-valued functions, as in y = f (x), with points evenly distributed along the x-axis, such as acquired time-varying waveforms.

• The graph also accepts several data types, which minimizes the extent to which you must manipulate data before you display it.

Displaying a Single Plot on Waveform Graphs

• For single plot, the waveform graph accepts several data types.

• E.g the graph accepts a single array of values, interprets the data as points on the graph and increments the x index by one

starting at x = 0.

• The graph also accepts a cluster of an initial x value, a delta x and an array of y data.

• The graph also accepts the waveform data type, which carries the data, start time and delta t of a waveform.

Page 39: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

What is waveform data type?

• The waveform data type is just another data type like numeric,Boolean etc. It carries the data, start time and delta t of a waveform.

• You can create a waveform using the Build Waveform function.

• Many of the VIs and functions you use to acquire or analyze waveforms accept and return waveform data by default.

• When you wire waveform data to a waveform graph or chart, the graph or chart automatically plots a waveform based on the data, start time and delta x of the waveform.

• When you wire an array of waveform data to a waveform graph or chart, the graph or chart automatically plots all waveforms.

• The waveform graph also accepts the dynamic data type, which is for use with Express VIs. In addition to the data associated with a signal, the dynamic data type includes attributes that provide information about the signal such as the name of the signal or the date and time the data was acquired.

• Attributes specify how the signal appears on the waveform graph.

Page 40: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

Displaying Multiple Plots on Waveform Graphs

• The waveform graph accepts several data types for displaying multiple plots as well

• The waveform graph accepts a 2D array of values, where each row of the array is a single plot. The graph interprets the data as points on the graph and increments the x index by one, starting at x = 0.

Wire a 2D array data type to the graph, right-click the graph and select Transpose Array from the shortcut menu to handle each column of the array as a plot.

This is particularly useful when you sample multiple channels from a DAQ device because the device can return the data as 2D arrays with each channel stored as a separate column.

• The waveform graph also accepts a cluster of an initial x value, a delta x value, and a 2D array of y data. The graph interprets the y data as points on the graph and increments the x index by delta x, starting at the initial x value.

• This data type is useful for displaying multiple signals that are sampled at the same regular rate.

• The waveform graph can also accept a plot array where the array contains clusters. Each cluster contains a 1D array that contains the y data. The inner array describes the points in a plot, and the outer array has one cluster for each plot.

Page 41: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

WAVEFORM CHARTS• Technically, waveform chart is a special type of numeric indicator that displays one or more plots of data typically

acquired at a constant rate.

• They can also display single or multiple plots

• The major difference from waveform graph is that waveform chart maintains a history of data or buffer from previous updates.

Displaying a Single Plot on Waveform Charts

• You can wire a scalar output directly to a waveform chart. If you pass the chart a single value or multiple values at a

• time, LabVIEW interprets the data as points on the chart and increments the x index by one starting at x = 0. The chart treats these inputs as new data for a single plot.

• Waveform chart also accepts the waveform data type which carries the data, start time and delta t of a waveform.

Displaying Multiple Plots on Waveform Charts

• Waveform charts can display multiple plots together using the Bundle function located on the Cluster palette.

• In Figure shown on next slide, the Bundle function bundles the outputs of the three VIs to plot on the waveform chart.

• The waveform chart terminal changes to match the output of the Bundle function.

Page 42: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

• To add more plots, use the positioning tool to resize the Bundle function.

• You can also use the waveform data type to create multiple plots on a waveform chart. Use the Build Waveform function to plot

time on the x-axis of the chart and automatically use the correct interval between markers on the x-scale of the chart. It is useful

for plotting data that is not evenly sampled because each data point has its own time stamp.

• If you cannot determine the number of plots you want to display until run time, or you want to pass multiple points for multiple

plots in a single update, wire a 2D array of numeric values or waveforms to the chart.

• By default, the waveform chart treats each column in the array as a single plot. You can change it to vice versa by clicking

transpose if you want. In that case each row of the array will taken as a single plot.

Page 43: Arrays - Delhi Universitybcas.du.ac.in/wp-content/uploads/2020/04/B.ScH...That will make program lengthy, difficult to write and comprehend. • Instead if you have array marks[],

XY GRAPH

• The XY graph is a general-purpose, Cartesian graphing object that plots multivalued functions, such as circular shapes or waveforms with a varying time base.

• It displays any set of points, evenly sampled or not.

• The XY graph can display plots containing any number of points.

• Just like waveform graph and chart, it also accepts several data types e.g a cluster that contains a X array and a Y array. It also accepts an array of complex data in which the real part is plotted on the x-axis and the imaginary part is plotted on the y-axis

• And similarly you can have a single plot or multiple plots as well on XY graph

• Figure below shows an example of an XY graph.