Skip to content Skip to navigation

OpenStax_CNX

You are here: Home » Content » Accessing Previous Loop Data

Navigation

Lenses

What is a lens?

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

This content is ...

Affiliated with (What does "Affiliated with" mean?)

This content is either by members of the organizations listed or about topics related to the organizations listed. Click each link to see a list of all content affiliated with the organization.
  • NSF Partnership display tagshide tags

    This module is included inLens: NSF Partnership in Signal Processing
    By: Sidney BurrusAs a part of collection: "LabVIEW Graphical Programming Course"

    Click the "NSF Partnership" link to see all content affiliated with them.

    Click the tag icon tag icon to display tags associated with this content.

  • National Instruments display tagshide tags

    This module is included in aLens by: National InstrumentsAs a part of collection: "LabVIEW Graphical Programming Course"

    Comments:

    "A full introductory course on programming with LabVIEW."

    Click the "National Instruments" link to see all content affiliated with them.

    Click the tag icon tag icon to display tags associated with this content.

Also in these lenses

  • Lens for Engineering

    This module is included inLens: Lens for Engineering
    By: Sidney Burrus

    Click the "Lens for Engineering" link to see all content selected in this lens.

  • eScience, eResearch and Computational Problem Solving

    This module is included inLens: eScience, eResearch and Computational Problem Solving
    By: Jan E. OdegardAs a part of collection: "LabVIEW Graphical Programming Course"

    Click the "eScience, eResearch and Computational Problem Solving" link to see all content selected in this lens.

Recently Viewed

This feature requires Javascript to be enabled.

Tags

(What is a tag?)

These tags come from the endorsement, affiliation, and other lenses that include this content.
 

Accessing Previous Loop Data

Module by: National Instruments. E-mail the author

When programming with loops, you often need to access data from previous iterations of the loop. For example, you may have a VI that reads the temperature and displays it on a graph. If you want to display a running average of the temperature as well, you need to use data generated in previous iterations. Two ways of accessing this data include the shift register and the Feedback Node.

Shift Registers

Use shift registers on For Loops and While Loops to transfer values from one loop iteration to the next. Shift registers are similar to static variables in text-based programming languages.

shiftregs.png A shift register appears as a pair of terminals, shown in Media 1, directly opposite each other on the vertical sides of the loop border. The right terminal contains an up arrow and stores data on the completion of an iteration. LabVIEW transfers the data connected to the right side of the register to the next iteration. Create a shift register by right-clicking the left or right border of a loop and selecting Add Shift Register from the shortcut menu.

A shift register transfers any data type and automatically changes to the data type of the first object wired to the shift register. The data you wire to the terminals of each shift register must be the same type.

To initialize a shift register, wire any value from outside the loop to the left terminal. If you do not initialize the shift register, the loop uses the value written to the shift register when the loop last executed or the default value for the data type if the loop has never executed.

Use a loop with an uninitialized shift register to run a VI repeatedly so that each time the VI runs, the initial output of the shift register is the last value from the previous execution. Use an uninitialized shift register to preserve state information between subsequent executions of a VI. After the loop executes, the last value stored in the shift register remains at the right terminal. If you wire the right terminal outside the loop, the wire transfers the last value stored in the shift register.

You can add more than one shift register to a loop. If you have multiple operations within a loop, use multiple shift registers to store the data values from those different processes in the structure. The block diagram in Figure 1 uses two initialized shift registers.

Figure 1
Figure 1 (shiftregex.png)

Stacked Shift Registers

To create a stacked shift register, right-click the left terminal and select Add Element from the shortcut menu. Stacked shift registers let you access data from previous loop iterations. Stacked shift registers remember values from previous iterations and carry those values to the next iterations.

Stacked shift registers, as shown in Figure 2, can only occur on the left side of the loop because the right terminal only transfers the data generated from the current iteration to the next iteration.

Figure 2
Figure 2 (stackshiftregex.png)

If you add two more elements to the left terminal, values from the last three iterations carry over to the next iteration, with the most recent iteration value stored in the top shift register. The second terminal stores the data passed to it from the previous iteration, and the bottom terminal stores data from two iterations ago.

Feedback Nodes

feedback.png The Feedback Node, shown in Media 4, appears automatically in a For Loop or While Loop if you wire the output of a subVI, function, or group of subVIs and functions to the input of that same VI, function, or group. Like a shift register, the Feedback Node stores data when the loop completes an iteration, sends that value to the next iteration of the loop, and transfers any data type. Use the Feedback Node to avoid unnecessarily long wires in loops. The Feedback Node arrow indicates in which direction the data flows along the wire.

You also can select the Feedback Node on the Structures palette and place it inside a For Loop or While Loop. If you place the Feedback Node on the wire before you branch the wire that connects the data to the tunnel, the Feedback Node passes each value to the tunnel. If you place the Feedback Node on the wire after you branch the wire that connects data to the tunnel, the Feedback Node passes each value back to the input of the VI or function and then passes the last value to the tunnel. The Accessing Previous Data VI exercise contains an example of this behavior.

Content actions

Download module as:

PDF | EPUB (?)

What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

Downloading to a reading device

For detailed instructions on how to download this content's EPUB to your specific device, click the "(?)" link.

| More downloads ...

Add module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks