From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Custom Array Manipulation Using Conditional Loop Tunnels

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview
LabVIEW now features an option to conditionally send data out of a loop tunnel. Auto indexing an array each side of a for loop will allow you to perform custom array operations such as only taking out odd or even data


Description
This example uses the "Quotient & Remainder" function to make sure that only even or odd numbers are added to the output array. Instead of this function you could use any of the control structures, logic or math functions in LabVIEW to build a specific array function. The one I've built quite simply allows for all of the data, none of the data, or odd and even sets of the data to be extracted.


Requirements

  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Choose the data to extrate
  2. Run VI

 

Additional Information or References
VI Block Diagram

 Block Diagram.png

 

 **This document has been updated to meet the current required format for the NI Code Exchange.**

Daniel Harryman MEng
CLA, CPI

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
mtedaldi
Member
Member
on

Awesome. I did not know about this Function! This alone makes it almost worth to switch to LV 2012!

--
Marco Tedaldi, University of Zurich, CLAD
DanHarryman
Member
Member
on

You can do this in older versions of LabVIEW as well just with case structures inside the Loop. I'll upload an image of the old functionality.

Daniel Harryman MEng
CLA, CPI
mtedaldi
Member
Member
on

Thank you for adding a solution for older versions. In my experience this solution comes with a big performance penalty compared to the auto-index solution.

I'll try to run some benchmarks to test it.

--
Marco Tedaldi, University of Zurich, CLAD
DanHarryman
Member
Member
on

No problem, I think you might be right about the performance of the older version. If you do benchmark it please post your findings on here.

Daniel Harryman MEng
CLA, CPI
mtedaldi
Member
Member
on

Ok, I've made a test VI and wrote a little document Benchmark "build array" vs. "auto indexing" in a loop (since it seems I can't add uploaded files to comments).

Conclusion: There is a huge speed penalty on "build array" against "auto index".

--
Marco Tedaldi, University of Zurich, CLAD
FabriciusLopes
Member
Member
on

I don't notice this function until now ! This makes my life a lot easier. Thanks a lot.