LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

sort array

Solved!
Go to solution

I have attached a simple VI to feed an array the latest values on top.

Please if anyone can suggest any better way.

0 Kudos
Message 1 of 8
(3,607 Views)

Hi alok.p,

               Can you repost it in LV2009.So that I can look at it.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Thanks as kudos only:)
0 Kudos
Message 2 of 8
(3,605 Views)
0 Kudos
Message 3 of 8
(3,601 Views)

You can do that in different way. Here is an example

 

array on top.png

 

Darren's nugget is a very good example for this.

-----

The best solution is the one you find it by yourself
0 Kudos
Message 4 of 8
(3,591 Views)

in 1st diagram why sort array function is used inside for loop ( it may be outside ).

second diagram is just a standard use of sort array.

yes darren's nugget is very good
i am just asking that is my method optimized for performance or any other improvement is required

 

In my vi iteration count is just used as example to feed array actually they will be different elements.

0 Kudos
Message 5 of 8
(3,580 Views)

If you compare Darrens suggested with the one you did you'll see minimal differences, and then i'd suggested the one with the least code. 🙂

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 8
(3,572 Views)
Solution
Accepted by topic author a.p

@Alok.p wrote:

I have attached a simple VI to feed an array the latest values on top.

Please if anyone can suggest any better way.


I don't uderstand why you call the iteration terminal output "random no. will be feed to array", because it is certainly not a random number because the code guarantees that the current number is always larger than any existing number in the array (except in the first iteration where it is equal), the problem, as currently posed, makes no sense.

 

Let's assume you have an array with 10 elements (you should also resize the array indicator to actually show all 10 elements, currenty we only see 9) and you want to add the newest value at position 0 (independent of numerical sort order!), shifting all other elements up with each addition.

In this case, the following would be a solution that keeps the array statically allocated in memory. The elements will always be sorted in historical sort order, newest on top, and the array size is fixed at 10 elements, retaining the 10 most recent additions.

 

 

 

The button labeling is also misleading, because it is latch action, only one element will be added with each press. It should be called "add element" instead.

 

(Of coure an event structure would be better for the current code, (not shown)).

Download All
Message 7 of 8
(3,554 Views)

Ahhhhhh i was waiting for you to comment CA

some clarifications

I have used iteration terminal to feed my array but just as example actually these will be values coming from different parts of the program and may be greater or less than the previous values.

button label as add element will be replaced by certain condition.

event structure will not be needed because condition for adding elements in the array is progamatically defined not by user action( unless i use user events )

 

The truth about posting this VI was I knew you( CA ) will come up with a solution which will be less painted than my picture and this happenedSmiley Wink

 

0 Kudos
Message 8 of 8
(3,532 Views)