LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

combine dynamic 1D array into an 2D image array

Solved!
Go to solution

Hello,

I use AI channel to get a series DAQ data in the while loop and it can produce  1D array. I need to combine those dynamic1D array into an 2D image. Is there any way to do it without loosing much speed? 

I used to initialized a 1000 by 1000 zero array and filled it point by point. The system could not catch up with it. 

So I am now trying to fill an image line by line.

Thank you very much

Best regards

Yu

Download All
0 Kudos
Message 1 of 8
(440 Views)

Reshape Array

 

Try it out with the input of your 1D array and outputting a 2D array (drag it down to make it have 2 inputs for dimensions).

 

You may need to transpose the 2D output or reverse the lines or columns depending on the orientation of the data coming in to the array, but it should be faster than point-by-point.

0 Kudos
Message 2 of 8
(427 Views)

I recommend to go back to the basic tutorials because most of your code makes no sense at all.

 

  • You initialize a 500 size 1D array, not a 1000x1000 2D array.
  • You measure "NChan Nsamp", so you get an array of waveforms that you convert to a 1D array, even though the input is not dynamic data. How many channels? How many samples? Why do you generate waveforms instead of simple arrays? I doubt timing is relevant for images and you'll drop it anyway later.
  • Then you take that array and throw everything away except the first element, giving you a 1D array of size=1.
  • Then you place that single element into your initialized array.
  • They you also create an upper shift register that has absolutely no purpose, because you never use the right output.

At this point I would recommend to create a simple simulation of your inner FOR loop that generates random data and fills the array (all sized to the real code!). Leave the hardware out of it. See how far you get.

0 Kudos
Message 3 of 8
(408 Views)

Hello,

The array size I initialized could be changed at image size on the front panel. The saved default number is recorded as 500. When run the code, I would change it at 1000.

Shall I switch the measurement to 'Analog/Single Channel/Single Sample/DBL'? I only have one channel for analog input but many samples.

When I take several samples from the signal, I can only get one nonzero data. The rest of data was shown as zero no matter how many sample I take. So I just take one data. Is there any way to solve it?

Thank you very much

Best regards

 

 

0 Kudos
Message 4 of 8
(381 Views)

Thank you

I tried the reshape function with simulated data that I generated with random numbers.

But I found if I set the image size 1000 by 1000, the code response was very very slow. 

Is there any way to speed up the calculation?

Thank you very much

Best regards

 

0 Kudos
Message 5 of 8
(380 Views)

If you want all elements of a 1000x1000 2D array, the 1D array needs to have 1M elements before reshaping. reshaping should only happen once all data is acquired.

 

You are not doing any "calculations" just rearranging in memory. (... and possibly thrashing memory!)

 

Once you can post a simple simulation as requested, we can help you. Currently, the information is way too ambiguous.

 

0 Kudos
Message 6 of 8
(371 Views)
Solution
Accepted by topic author Rhapsody16

@Rhapsody16 wrote:

When I take several samples from the signal, I can only get one nonzero data. The rest of data was shown as zero no matter how many sample I take. So I just take one data. Is there any way to solve it?


If you only get one point per acquisition and want more than one, something is misconfigured (sorry, I don't have any drivers installed and I don't have your hardware).

 

If you only get one point per iteration, just autoindex to create a 1M size 1D array that you then reshape to 1000x1000. No need to jump through all these flaming hoops!

 

Here's one possibility (and it is nearly instantaneous!):

 

altenbach_0-1642004952020.png

 

0 Kudos
Message 7 of 8
(369 Views)

Thank you very much

Let me do the simulation data first

Best regards

 

0 Kudos
Message 8 of 8
(366 Views)