Example Code

Remove Rows with all Zeros from a 2D Array

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

This example shows how to remove all rows that contain all zeros from a 2D Array. This is useful if you have logged lots of data and want to isolate rows that actually contain data.

 

Description

There are often lulls in data-generating activity during an acquisition. This program sifts through a large collection of data and extracts the meaningful information. 

There is one implementation presented here, that uses auto indexing to iterate rows of the 2D array and case structures to control the conditional inclusion of non-zero data.

 

"Not equal to zero?" function checks if each single row element is zero or not.

"OR Array Elements" combines the results for all row elements and determines if the row needs to be saved to the new output array or not.

The "Index Array" function is used to allocate memory before executing the loop. This is important to prevent new memory allocations in every loop iteration which would happen if using "build array" function or conditional indexed output tunnels.


Requirements

 Software

  • LabVIEW Base Development System 2012 (or compatible)
  • If running in a Real-Time context, you will need the LabVIEW Real-Time Module 2012 (or compatible)

 Hardware

  • No hardware is necessary to use this example VI

 

Steps to Implement or Execute Code

  1. Download and open the attached file
  2. Follow the instructions in Front Panel of "Remove Rows with all zeros from 2D array NI Verified.vi" and run the program

 

Additional Information or References

Remove Rows with all zeros from 2D array LV2012 NIVerified.vi - Front Panel.png 
Remove Rows with all zeros from 2D array LV2012 NIVerified.vi - Block Diagram.png
 
**The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text ‘NIVerified’. Read here for more information about the new Example Guidelines and Community Platform.**
-John Sullivan
Problem Solver

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

Comments
Todd S.
NI Employee (retired)
on

Please include a screenshot.  Thanks!

Todd S.
LabVIEW Community Manager
National Instruments
Ledang
Member
Member
on

Hi

I just found your VI but I could't download due to general errors. Could you please reload the zip file. I really need it,

Thanks

arelone

Now_With_Underscores
NI Employee (retired)
on

Recreated and uploaded.  Apologies the link was busted.  Have fun churning your datas.

-John Sullivan
Problem Solver
Mads
Active Participant
Active Participant
on

Rescaling arrays (using the build or delete functions e.g.) is *extremely* costly (speed and memory-wise) so you should always try to avoid doing it repeatedly, especially on potentially large arrays. So instead of building the result array one element at a time, try reusing the existing one as it is, and then rescale it once afterwards.

I've attached one possible implementation of this here. It's not the optimal solution either, but it keeps the code simple and removes the largest performance issue. (A comparison on a random PC: On a 1000x1000 array where 10% of the rows are all zeroes this VI will run in 9 ms, instead of the original's 1300 ms.)