From Thursday, May 23rd (05:00 PM CDT) through Friday, April 24th (1:30 AM 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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Explenation code

Can somme body explain me this code.

 

ArneVDS_0-1713697185310.png

 

0 Kudos
Message 1 of 5
(927 Views)

Hi ArneVDS,

 

This takes all even values from an input array and sorts them in descending order. The first part with the loop tests for divisibility by 2 (with function "Quotient & Remainder" and checking whether the remainder equals 0) and keeps only even values (using a conditional auto-indexing tunnel to select which values go in the output array). Then the remaining values are sorted in ascending order (with function "Sort 1D Array"), and then reversed (with function "Reverse 1D Array"), making them sorted in descending order.

 

However there may be some problems:

1. The input array should be outside of the loop, reading it at each iteration is inefficient;

2. Why using a while loop instead of a for loop? You already know the number of iterations since the beginning;

 

raphschru_0-1713706103703.png

 

 

3. Also, using real numbers for testing divisibility seems unusual. Maybe an integer type (like I32) should be used instead.

Then the code can be optimized by using a bitwise operation:

 

raphschru_1-1713706178435.png

 

Attached my VI.

 

Regards,

Raphaël.

Message 2 of 5
(902 Views)

One more option:

Decimate the array…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 5
(877 Views)

As has been said, it seems pointless to "explain" poor and inefficient beginner code, especially if there are glaring flaws. Learning LabVIEW from examples require sane examples, not some random pictures found in a dark corner of the internet. Can you explain where you found that?

 

There is no concept of odd/even unless the input is all integers and the only way to ensure that is to use a blue datatype.

 

(Note that Gerd's decimation "solution" above takes all elements with even index, independent of value, while you apparently want all even values, a completely different problem.)

0 Kudos
Message 4 of 5
(867 Views)

Hi Christian,

 


@altenbach wrote:

(Note that Gerd's decimation "solution" above takes all elements with even index, independent of value, while you apparently want all even values, a completely different problem.)


You're right, I mis-interpreted the code. Seems it was too late yesterday when writing the message…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 5
(835 Views)