06-10-2010 03:08 PM
I'm not quite getting the array 'acrobatics' right.
I want to perform a function on a 1D array similar to the 'Decimate Array' function except instead of sorting out single elements, I want it to sort by chunks of elements at a time. For instance, if I input a 1D array of some length, it should output the first 5 elements in one array, the next 5 elements in another array, the next 5 elements back to the first array, etc. How might I go about doing that?
Thanks for your help.
Luke
06-10-2010 04:01 PM
Use the Index Array function in a loop. Get 5 elements at one time. You will need a case structure to select which output array to use. You can control that by dividing the iteration terminal (i) by 5 using the Quotient and Remainder function. If the quotient is even, select one array, if odd select the other. Or you could use a boolean with a shift register and toggle the boolean each loop. The boolean will be T-F-T-F and so on, and can be wire to the case structure to alternate between output arrays.
Try coding it yourself. Post you code if you run into problems.
06-10-2010 04:07 PM
Not really Rube material, but it feels a bit inelegant to me. I chose to pad the input array, you could also truncate if you wanted. This will let you specify the number of arrays (2 in your case) and the chunk size (5). The output is a 2D array where each row corresponds to one of the desired arrays.
06-10-2010 04:56 PM
Awwww, Darin. You went and did his homework for him. How is the guy going to learn how to code on his own?
06-10-2010 06:15 PM
tbob wrote:Awwww, Darin. You went and did his homework for him.
How is the guy going to learn how to code on his own?
I know of no better teaching instrument than a well-written example. If the OP figures out how the code works he'll learn plenty as far as I am concerned. His history gives me no indication that he is looking for us to do any of his work. Last I checked, LV ships with a ton of examples so they must think it is a good thing (even if many of them are sketchy).
LV itself is very easy to learn, what is harder to teach and learn is the thought processes that go into problem solving. In this case, he should be thinking beyond two arrays with a fixed chunk size of 5 and instead thinking early on about code that is adaptable to other problems.
As an added bonus, this way someone else can post their version which makes mine look excessively complicated and I get to learn as well.