11-03-2012 03:55 AM
I have attached a simple VI to feed an array the latest values on top.
Please if anyone can suggest any better way.
Solved! Go to Solution.
11-03-2012 03:58 AM
Hi alok.p,
Can you repost it in LV2009.So that I can look at it.
11-03-2012 04:02 AM
11-03-2012 08:59 AM
You can do that in different way. Here is an example
Darren's nugget is a very good example for this.
11-03-2012 10:32 AM
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.
11-03-2012 12:14 PM
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
11-03-2012 03:15 PM - edited 11-03-2012 03:19 PM
@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)).
11-03-2012 11:19 PM
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 happened