LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Rapidly converting a length (m*n) 1D array to an m by n 2D array

Solved!
Go to solution

Hello all,

I am looking for a way to speed up a particular step in a VI I use. I have a 1d array of length m*n that I want to convert into a 2d array of dimensions m and n. Currently I feed the 1d array into a for loop and use split 1d array to cut the 1d array into a piece of length m and then another piece with the remainder and then each of those m-length pieces forms a new row in another array. I'm sure that's not clear, so I've attached the section of the VI that does this. The VI works just fine, it's just slower than I'd like. I'll regularly grab a 1D array that's 1024*8000 long and this code is definitely the rate-limiting step. Is there something I can do to make this run faster?

 

Thanks very much for taking a look!

 

For context (though I doubt this important to answer my question) m is called "Sensor Width" and n is "Num of shots." I am sending a read command to an array of 1024 photodiodes which report their last "Num of shots" measurements. This is output as a 1d array that is pixel1shot1, pixel2shot1, pixel3shot1... pixel1024shot1, pixel1shot2... etc. and I'd like a 2d array that is pixel by shot.

0 Kudos
Message 1 of 3
(2,321 Views)
Solution
Accepted by topic author Damrauer

There's a reshape array function on the array palette.

Message 2 of 3
(2,313 Views)

Well now I feel dumb. Reshaping the 1024 by 8000 array the old way took about a minute, and now it's less than a quarter second with the native VI. Thank you for increasing my efficiency by a factor of 300+!

Message 3 of 3
(2,303 Views)