Example Code

Sort an Array of Clusters by Any Element in the Cluster

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 VI sorts an array of clusters by one of its cluster elements.

 

Description

This VI contains an array of clusters. The user can choose any element in the clusters in the "Element to Sort By" listbox. The clusters will be sorted according to that element.

 

Requirements

  • LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code

  1. Open the attached Sort Array of Clusters 2012 NIVerified.vi
  2. Run the VI
  3. Select an entry from the "Element to Sort by" control
  4. Note that the output array is now sorted based on your selection

 

Additional Information or References

 

Front Panel 1.PNG

 

Block Diagram

2.png

 

 

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

Product Support Engineer
National Instruments

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

Comments
Marc...
Member
Member
on

Hi could you help me, i seem i can't get it to go from the max to min instead of min to max and when i have 2 or more that are equal to each other i want them to be sorted by an other element of the cluster.

I would appreciate it if you could help me on that ( i have Labview 8.5)

EricS.
NI Employee (retired)
on

Marc you're right.  I discovered this VI will not work if any of the values are the same.  For example change all Number 5s to "2000" and the resulting array will have two entries of one of the clusters and zero entries of the last cluster.

This is because the "search 1D array" function will return the index of the first matching value regardless of if there are other mathing values.

Eric S.
AE Specialist | Global Support
National Instruments
carlos_camargo
Member
Member
on