LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

little program problem

I have a problem with my program. I have a dataset of X,Y dates and if there is a number in the y-dates smaller or equal as 1, the program should delete this y-number with its corresponding x-number!
The program always only deletes von number and not all!
 
Could somebody help me please!
 
Thanks in advance!
 
 
Labview 7.1 on Windows 2000
0 Kudos
Message 1 of 9
(3,980 Views)
Hi Peter,
 
See the modification I've made. My Idea was to eliminate those unwanted data pairs from the end of the array, not from the beginning. In this way there will be no change in the index number of those unwanted array elements during elimination process!
 
Regards.
0 Kudos
Message 2 of 9
(3,962 Views)

Thank you for your program!

I found another solution... attachement!

Best regards,

 

P.F.

Labview 7.1 on Windows 2000
0 Kudos
Message 3 of 9
(3,955 Views)
Hmm, yes, this is another solution.
 
I've read somewhere in the forum that: " There are many ways to do anything in LV, but your way is certainly not the best one." I don't remember who the author was!
 
Ohh, by the way, I think my code has better memory performanceSmiley Tongue
 
Cheers.
Soroush.
0 Kudos
Message 4 of 9
(3,943 Views)
It was more along the lines of "but yours is the worst" and it was in the LV proverbs thread. I think it was Spaceman Spiff.

___________________
Try to take over the world!
0 Kudos
Message 5 of 9
(3,930 Views)


@PETER_AUT wrote:

I found another solution... attachement!



One little comment on your last version: You should not wire the array size to the loop, because the actual number of iterations will be determined by the shortest autoindexing array anyway. (If you would make X a few elements short, it would only iterate for the number of elements in the x array).

If any loop input is autoindexing, wiring N is only useful if you need to make the total iteration number less than any of the autoindexing array sizes. 😉

Your solution is fine for small to medium sized arrays. If you are dealing with huge arrays and are pressed for memory and performance, you should allocate a full sized array at the beginning of the loop (or even re-use the input arrays). Inside the loop you would index and replace elements, read at index [i] but replace at a different index (i2) that does not increment if a value is skipped (index i2 maintained in a shift register).

At the end of the loop, trim the extra tail using reshape array with a length determined from the final i2 value. 🙂

Might be a nice exercise for you to implement this! 😉

0 Kudos
Message 6 of 9
(3,910 Views)
A question about memory performance:
 
Will a new copy of an array be created in the memory when we delete an element from that array?
 
If this is true, none of these solutions are good enough.Smiley Indifferent
0 Kudos
Message 7 of 9
(3,884 Views)


@Soroush wrote:
A question about memory performance:
 
Will a new copy of an array be created in the memory when we delete an element from that array?
 
If this is true, none of these solutions are good enough.Smiley Indifferent



For your enjoyment, I have made a little comparison of the various algoritms. Remember, you can always go to "tools...advanced...show buffer allocations" to see where new array allocations take place.
 
"Delete from array" is "in-place" and does not allocate new memory for the output. However it does way too much work for this task. Remember, every time it deletes an element, it needs to shift all higher numbered elements down one slot. The last element of the array will get moved as many times as you delete elements. This can get very expensive with large arrays. ( Only if deleting an element is a very rare event, this is still a good solution). It does not really matter if you do it from the end or from the beginning!
(Notice that your code is incorrect because the last element does not get rejected, even if it should. Try with the default data of the original post)
 
"Built array" is also problematic with large arrays because the code does not know how big the output arrays will be. LabVIEW will make an estimate, but every time the ceiling is hit, memory needs to be re-allocated and the estimate revised.
 
I show two versions using "replace array element". If you autoindex the inputs (replace I), new arrays get allocated at the shift register to ensure that the data is valid. If you index inside the loop (Replace II), the array is re-used and we get another doubling in speed. 🙂
 
The attached program shows some typical execution times as a function of array size and algoritm. The simulted data causes about 50% of elements to be deleted. As you can see, the time differences are very dramatic!
 

Message Edited by altenbach on 08-11-2005 09:08 AM

Download All
Message 8 of 9
(3,867 Views)
Just Thank you!
 
Educating reply and example code. I didn't miss any point. Be quite sure!Smiley Happy
 
It is of my pleasure to confess that my code was the worst, as the old LVese proverb said!Smiley Very Happy
 
I only didn't understand why you said that my code is incorrect. It is the same as what you done in "Delete" mode, but this has the least importance in my mind.
0 Kudos
Message 9 of 9
(3,839 Views)