LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatic way to get data from queue and place into 2D array

Solved!
Go to solution

Is there a better way to do this, or what I am really trying to figure out if there is a programmatic way to do this. 

 

There are 30 items in the queue, each item is a 1D array contains 200 elements. Currently there are three channels in the program, but this code will be used in other programs with varying channels (hopefully user selectable), and it sure seems like there is a cleaner way to do this. 

 

[img]https://live.staticflickr.com/65535/32899261117_0fe0368c4d_b.jpg[/img]

 

Thanks!

0 Kudos
Message 1 of 7
(1,186 Views)

Please embed images into the post using the given tools (camera icon in toolbar of edit window). Linking to offsite places is discouraged.

Your code does not make a lot of sense. I am sure there is a 10x easier way (At least combine the two FOR loop into one).

 

We cannot run pictures. Can you attach the actual VI instead? What are typical values and array sizes?


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 2 of 7
(1,158 Views)

I am using the queue as a pre-trigger, and when the data is triggered I need all the items in the queue. I am sampling at 2KHz and read 200 samples at a time, so that is what each item in the queue is. When I get the items from the queue, they are 1D arrays, and the final data structure I need is a 3*2000 array. The array from the queue looks like this:

 

Channel 1 200 samples

Channel 2 200 samples

Channel 3 200 samples

Channel 1 Next 200 samples

Channel 2 Next 200 samples

Channel 3 Next 200 samples

 

I have tried reshaping the array several different ways, but I can't get it to where all of channel 1 data is in the first row, channel 2 is in the second row and so on. I wrote a simulated VI so you can understand what I am trying to do.

 

0 Kudos
Message 3 of 7
(1,151 Views)

Can you guarantee that all arrays have the same length and that the number of rows is divisible by the number of channels? Is the number of channels variable or constant?


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 4 of 7
(1,148 Views)

Here's one quick alternative. Seems simpler. Same result.

 

ProcessArray.png

 

(That said, the overall code does not feel right, with the queue filling up to 30 elements and you never actually remove anything from the queue. I am sure there is a better way overall, but I don't know the rest of your code)


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
Message 5 of 7
(1,144 Views)

Yes, all the arrays will have the same length as they are coming from DAQmx and I have specified the number of samples to read (200). The number of channels will be constant in each program.

 

The sample VI I attached does nothing with the queued data, the real program is different.

0 Kudos
Message 6 of 7
(1,131 Views)
Solution
Accepted by adekruif

@altenbach wrote:

Here's one quick alternative. Seems simpler. Same result.

 

...

 

(That said, the overall code does not feel right, with the queue filling up to 30 elements and you never actually remove anything from the queue. I am sure there is a better way overall, but I don't know the rest of your code)


Back from NI week and looking at this again and I came up with a programmatic way to do this. I changed the numbe of channels of 5 to check that the solution I came up with worked for a different number of channels! Thanks for the help Altenbach!

 

ProgrammaticMethod.png

Message 7 of 7
(1,061 Views)