LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

build array from only one condition of a case structure

Solved!
Go to solution

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 

0 Kudos
Message 1 of 12
(11,443 Views)
Can you attach you vi so that we can better understand what you are trying to do?
Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 2 of 12
(11,435 Views)

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:

 

 

  1. Start with an empty array of type T.  Why empty?  Because you haven't started testing the values yet. Uses INITIALIZE ARRAY or an empty ARRAY CONSTANT to create it.
  2. Wire the empty array into a SHIFT REG on a FOR loop. Why?  You're going to have a CHANCE to modify (or not) this value on every iteration. Maybe you will, maybe you won't - you don't know so you can't use autoindexing here.
  3. Run the starting array A into a FOR loop, and let autoindexing pick them out for you.
  4. Inside the loop, the autoindexing feeds you ONE value of type T.  Do whatever test you need, and get a boolean result.
  5. Have a CASE structure inside the loop, with the selector wired to your boolean test result. Why a CASE?  You need to do one thing if TRUE and something else if FALSE.
  6. In the TRUE case, what do you need to do? If I read you correctly, nothing.  So just wire the left side SHIFT REG into the CASE structure and right on out to the right-side SHIFT REG.  That leaves the value of the array you're building unchanged in the TRUE case.
  7. In the FALSE case, what do you need to do?  You need to BUILD ARRAY, so plop a BUILD ARRAY function inside the FALSE case.  The array you're building already comes into the CASE structure, wire that tunnel into the top BUILD ARRAY terminal.  The array you're building already leaves the CASE structure on the right; wire the output of the BUILD ARRAY to that tunnel.
  8. That leaves one terminal on the BUILD ARRAY unwired; guess what you should do with that.  That's right, wire the value that you tested and it failed.

 

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: 

Picture 2.png

 

Hope that helps 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 3 of 12
(11,423 Views)

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.

 

Message Edited by adamkse on 10-31-2009 09:45 PM
0 Kudos
Message 4 of 12
(11,392 Views)
Solution
Accepted by topic author adamkse

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

 

 

 

----------------------------------------------------------------------------------------------------------------
Founding (and only) member of AUITA - the Anti UI Thread Association.
----------------------------------------------------------------------------------------------------------------
Download All
0 Kudos
Message 5 of 12
(11,381 Views)

ah i see now. thank you very much. this should help me out greatly.

 

Adam 

0 Kudos
Message 6 of 12
(11,377 Views)
Hi I have a similiar problem I'm trying to get all the index values of an array that have element value of greater than five. I want to put these into a new array. The problem is I keep getting zero's as the default value on the case structure. I've attached the file could somebody help a labview newbie.
0 Kudos
Message 7 of 12
(11,269 Views)

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:

False.PNG

 

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).

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 8 of 12
(11,266 Views)

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

0 Kudos
Message 9 of 12
(11,208 Views)

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. 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 10 of 12
(11,197 Views)