From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
06-20-2013 03:41 AM - edited 06-20-2013 03:44 AM
Hi all
I want to have a "demultiplexer" block that, having one (2Nx1) array as input, will split the data in two (Nx1) arrays as output wether the index of the first array is even or odd......
At first I tried to implement this with a simple case structure in a while loop:
But this doesn't work because I can ony run this .vi when the outputs of the case have option "Use default if unwired" set on. And this will produce not a pair of (Nx1) arrays, but a pair of (2Nx1) arrays. The first array will be [value, 0, value, 0, .....] and the second will be [0, value, 0, value....]
I want to get rid of those zeros....
Any hints?
Thanks in advance!
Solved! Go to Solution.
06-20-2013 03:47 AM - edited 06-20-2013 04:01 AM
Try the decimate array function. That's probably all you need.
Here are a few general comments to your code in general:
06-20-2013 03:57 AM
I feel like an idiot, I have been looking in the "array" functions three times...
Thanks, this is exactly what I was looking for.
06-20-2013 04:19 AM
@altenbach wrote:
Try the decimate array function. That's probably all you need.
Here are a few general comments to your code in general:
- Since the number of iterations is known before the loop starts, you need a FOR loop. No need to wire N or compare the iteration count. It will iterate for all elements in the autoindexing input array automatically, then exit the loop. Also, output indexing on a FOR loop is much more efficient, because the array sizes of the outputs can be determined and exactly allocated before the loop starts. With a while loop, labview cannot do that.
- If you have LabVIEW 2012, you could use conditional indexing on the output tunnels.
- You could wire the remainder directly to the case structure and make one case 1 and the other 0. Less code! (See my signature).
- To check for odd vs. even, a logical AND with 1 is sufficient and more efficient.
- The "-1" belongs before the loop because it needs to be done only once (well, the compiler recognized loop invariant code and will in fact create compiled code as if the "-1" were before the loop, but why not be explicit?)
- When creating a code screenshot, try no to select anything. These black dotted outlines are distracting.
Well actually what I used for screenshot was the code "epurated" from the off topic parts... in the While loop I do some other stuff so that's why it was there instead of a For.
About the -1 you're right, I just quickly added a part to give the While loop the exit condition because of the "other stuff" removed from it, so there was not that kind of optimization.
The use of (x AND 1) to decide if it is even or odd is a very nice idea...