10-30-2009 08:02 PM
hey guys,
I have a for loop that passes an array into a case structure. i want to build an array of the values that pass into the false condition but i cant seem to do it. i only want the false values added to this new array, i do not want to add zeros if it is true. i tried the build array and loops with shift registers but i must be missing something.
If someone can point me in the right direction that would be great.
Thanks
Adam
Solved! Go to Solution.
10-30-2009 08:37 PM
10-31-2009 12:29 AM
You're using imprecise terminology so that it's hard to understand what you're asking.
Let's see if I can restate it, and maybe this matches what you need.
You have an array A of values of type T (T = integer, boolean, string, cluster, you name it).
You want to subject each value to some sort of test, with a boolean result.
You want a new array of just the values that fail this test.
Is that right?
If so, then just take that task apart:
The FOR loop will automatically examine every value in A, when it stops, the SHIFT REG on the right can be wired to an indicator or whatever you want to do with the result.
In pseudo-code, it looks like this:
B = [T] // empty array of type T
For each A in A[ ]
If Test(A)
// do nothing
else
B[ ] = BUILD ARRAY(B[ ], A)
end if
end for
Here I used a < 10 function as the test:
Hope that helps
Blog for (mostly LabVIEW) programmers: Tips And Tricks
10-31-2009 04:44 PM - edited 10-31-2009 04:45 PM
What steve posted is exactly what i want to do. Sorry for that bad descrition.
The only difference between mine and the one you posted is that i have two case structures inside my loop one inside the other. it is the inner most case structure that i want to build the array from. i tried to wire the true conditions to the shift register but it resets to element zero when there is a true condition for some reason.
Here is my vi, sorry for it being uncommented.
10-31-2009 06:14 PM
Hi adamkse,
Here are a couple of vis for you to look at. I think they both do what you want, the second one is a better way.
Notes:
Take advantage of the indexing feature to eliminate indexing the arrays yourself. Then you don't have to change the for loop iterations if your input array's size changes.
You were resetting the "ucodes" array each time through the outer loop. So that was corrected.
The reason the second vi is better, is because building an array in a loop is usually a bad idea. LabView must do memory allocation as the array grows (doesn't have to if array stays very small). This can take time, so its best to avoid it. First you make the array as big as it possible can get, then replace items starting at zero. Keep track of the actual size with a shift register and then resize the array at the end.
I hope this helps,
steve
10-31-2009 06:32 PM
ah i see now. thank you very much. this should help me out greatly.
Adam
11-09-2009 03:42 PM
11-09-2009 03:51 PM
1... You're usually better off asking your separate question on a separate thread; here you'll only get the attention of those who responded to the original thread, plus a few old grizzlies doing some dumpster diving...
2... Your VI is doing exactly what you're telling it to:
When the test is FALSE, what are you sending out to be autoindexed into an array?
The above says you're using the default value for an I32, which is zero.
You cannot use autoindexing on an array where you sometimes want to append a value and sometimes you don't.
In that situation you must start with an empty array in a shift register, and BUILD ARRAY when you want to append to it (test = TRUE) and don't BUILD ARRAY when you don't (test = FALSE).
Blog for (mostly LabVIEW) programmers: Tips And Tricks
11-10-2009 05:10 AM
Hi I think I'm missing some thing fundamental. I've tried to put the build array into the case structure with an initializing array outside the loop connected to a shift register.
but nothing happens, Am I using the wrong types of arrays etc.
mm
11-10-2009 06:42 AM
What do you mean "nothing happens"?
You have a BUILD ARRAY function in BOTH the TRUE case and the FALSE case. Therefore, the test is irrelevant and you put the index into the array you're building regardless.
If the test is to be meaningful, you have to do something different if it fails than if it passes.
Blog for (mostly LabVIEW) programmers: Tips And Tricks