LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reshape 3D array

Solved!
Go to solution

I am trying to convert a 3D array into a 2D array such that each row corresponds to an AI channel, and the number of elements in each row is the samples read in multiple iterations of the inner FOR loop. I have attached a sample output where the reshaped array seems to be switching positions of the two channels with every iteration. What am I doing wrong?

 

Thanks,

lza

Download All
0 Kudos
Message 1 of 4
(116 Views)
Solution
Accepted by laz_2331

All you probably need is set the output tunnel to "concatenate" and it will remain a 2D array. You might have to transpose first, though.

 

 

There is a lot of weird stuff going on, for example the boolean output from the outer FOR loop us guaranteed to be true. The outer FOR loop also does not really do anything useful because the "reshaped" gets overwritten with every iteration. Why is the front panel maximized to the screen?

 

Why is the "inner loop" control inside the loop? Are you expecting it to change between iterations?

 

Most likely you could do the outer while loop for all the spinning and just accumulate the data in a shift register. Think state machine. In fact you know the final size of the data exactly, so you could pre-allocate that that size and replace a 2D section of data at the right positions when it comes in. Much easier on the memory manager.

Message 2 of 4
(92 Views)

snippet_FOR_Loop_2D.png

Thank you, altenbach. A concatenated array with transpose gives me the form I was looking for. 

 

"the boolean output from the outer FOR loop us guaranteed to be true." The outer FOR loop will run for more than one iteration (it was set to 1 to focus on the array issue).

"The outer FOR loop also does not really do anything useful because the "reshaped" gets overwritten with every iteration."  I will save each concatenated array to a separate file (work in progress...).

 

Thanks,

lza

0 Kudos
Message 3 of 4
(75 Views)

Sorry, I can't open your LabVIEW 2022 snippet, but why do you now have these two green local variables. they should not be needed if you use the correct mechanical action. Currently you also have a race conditions because that lonely sequence frame will not sequence anything, but will run in parallel to the rest of the code. If you want it to execute before the loop, wire one of the outputs to the loop boundary. Dataflow!

 

The boolean output of the outer loop still makes no sense, because the loop cannot end until it is true. The loop can never output a false there.

 

I still think a state machine (one loop and one case structure) would be significantly simpler that that pyramid of loops.

0 Kudos
Message 4 of 4
(36 Views)