LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why do both VI's function different?

Hello to all,
 
I've two VI's..in my opinion they should function the same but they aren't. VI 1 functions correctly.
Can someone explain this to me?
 
Tnx
 
Joyce
Download All
0 Kudos
Message 1 of 15
(3,497 Views)
They don't function the same because... they are not the same Smiley Surprised
 
what are they supose to do, anyway?
0 Kudos
Message 2 of 15
(3,490 Views)
They supose to remove the zero values from the array. In the 2.vi not all zero values are removed...but i think it has to do with the function of the shift-register and the order of the inputs into the index array. Am i right?
0 Kudos
Message 3 of 15
(3,487 Views)
Just debug !!!
0 Kudos
Message 4 of 15
(3,481 Views)
First of all, "Just debug" isn't very helpful (even with three exclamation points!!!).

Second, there is a more basic problem here, which is that you are going about this process wrong. If I understood what you are trying to do, you have an array of integers, say {0,1,2,5,2,0,3,6,0} and you want to simply remove all the elements that are zero to return {1,2,5,2,3,6}; correct so far?

The approach it looks like you are trying to implement is to examine each element and delete it from the array if it's a zero. This algorithm will work, but it has a couple problem. To begin with it has to examine every element in the array - even if there are no zeros in it. Plus the time required to perform this operation will increase as the size of the array increases. Added to this, the way you implemented the algorithm is very inefficient - check-out LV's documentation on "auto-indexing" for advice on how to handle arrays.

In any case, a far better approach is to use the built-in LV function that allows you to search a 1D array. The output of this function is either the index where the value exists in the array or a -1 if the value is not found. Put that function inside a WHILE loop and if it returns a value of 0 or greater, then delete the element. If it returns a -1, stop the loop. With this implementation the number of iterations will be equal to the number of zeros in the array +1 -- regardless of the size of the array.

Of course the best approach is to prevent the insertion of the zeros in the first place. In your code's top-most case structure, if the input is false (Why are you using local variables here? just wire the terminal associated with the control.) output an empty array, if the input is true, output an array with a single element of 5 in it. Now daisy-chain the array through each of the remaining case statements and in each: If the input is false pass the array through unmodified, but if the input is true append the proper value to the array.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 5 of 15
(3,467 Views)

Hi Mike,

Thanks for your answer. Your right that my methode was inefficient.

I tried your methode to avoid zero's with the use of emty arrays. But i don't know how i can put them in an 1-D array. Maybe you can help me with my vi?

Tnx

 

Message 6 of 15
(3,460 Views)
This is what I was talking about...

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 7 of 15
(3,442 Views)

Hi Mike,

Tnx for your help! Smiley Very Happy

Joyce

0 Kudos
Message 8 of 15
(3,429 Views)

I probably would do something like in the attached (4.vi or 5.vi, LabVIEW 8.2).

It's a bit more compact and more scaleable. I would even make the control an array of booleans (see 5.vi). Now the code stays the same even if you have 5, 20 or 50 booleans. 🙂 Add free labels for the elements if desired. Also reverse the array if you want it in descending order. Your call. 🙂

(All the other code mentioned does not scale well, and needs to be modified (and gets more complex!) whenever the number of booleans changes. Not good! :))



Message Edited by altenbach on 01-06-2008 01:10 AM
Download All
Message 9 of 15
(3,428 Views)


JoyceJacobs wrote:
They supose to remove the zero values from the array. In the 2.vi not all zero values are removed...but i think it has to do with the function of the shift-register and the order of the inputs into the index array. Am i right?

Here's a quick explanation:
The way you remove the elements only works if you proceed backwards from the end of the array as in 11.vi. If you do it as in 2.vi (removing elements from the beginning of the array) all the indices of the higher elements will change whenever an element is removed. So of you remove element 0, element 1 becomes element zero on the next iteration, element 2 becomes 1, etc.
For example if the array is 0,0,3,4,5 you would inspect and remove element #0 in iteration 0, In the next iteration, the array will be 0,2,3,4 but now you inspect element #1, which is 2 and the zero that was at position #1 originally has already move to index #0 and thus slipped through the cracks in your code. Your code never sees it and it will not be removed!
Message 10 of 15
(3,421 Views)