04-21-2024 06:00 AM
04-21-2024 08:32 AM - edited 04-21-2024 08:44 AM
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;
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:
Attached my VI.
Regards,
Raphaël.
04-21-2024 12:01 PM - edited 04-21-2024 12:02 PM
04-21-2024 01:19 PM
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.)
04-22-2024 12:57 AM
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…