LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

1d array into 2d array

Solved!
Go to solution

I have a 1d array of data I need to have in 2d.

Example.

1234123412341234...........   needs to be

1234

1234

1234

.

.

.

There is no set number of data points. The data come from daq read and can be 1-8 channels. So the 1d array will have 1-8 points repeated over and over (different data from same channel). The 2d array would strip out the 1-8 channels of data into 1-8 columns and hoverever many rows and I collect.

 

0 Kudos
Message 1 of 11
(63,044 Views)

There is a reshape array function in the Array palette. Just feed it with the number of row and colums, and it will convert 1D to 2D (or to any number of dimensions). 


Message Edité par chilly charly le 01-08-2009 11:14 PM
Chilly Charly    (aka CC)
Message 2 of 11
(63,043 Views)
Try "reshape array". 🙂
0 Kudos
Message 3 of 11
(63,040 Views)

Yea I had tried that with no luck. I went back and looked at the data and it isn't as I decribed. The data is a 1d array of waveform for 1-8 data points (variable size here).

The points (data) change each time a read is made. I would like to take them and create a file with 2d data that would be 1-8 rows (would use array size to get this) and as many colums as the read from the daq performs before it is stoped. There would be no set number of columns. As data is read for the daq the columns data is filled in.

 

  

0 Kudos
Message 4 of 11
(62,999 Views)
Solution
Accepted by bassinbc

Your data looks like plain arrays and not "waveforms" (which is a specific LabVIEW datatype). 😉

 

Typically, one would append columns instead of rows, but you can always transpose the array later for the indicator. Be aware that growing arrays without upper limit can get you in memory trouble, so you should have some checks in place. Growing arrays in fast loops is also inefficient, because each array resizing operation requires a new memory allocation.

 

 

(NOTE: This assumes you have a relatively new LabVIEW version. In older version, you need a feedback node or shift regsiter tied to the while loop. What is your LabVIEW version?))

 

Of course there are other ways to grow by columns directly using "insert into array", but that's equally memory inefficient.

 

If the final array size is typically similar, you should allocate a 2D array of NaN, sized with the upper limit of "# of colums" and then use "replace array subset" to fill it with real data.

 

 

Message Edited by altenbach on 01-09-2009 08:12 AM
Message 5 of 11
(62,978 Views)

You can use the Insert into Array function, with the row index set to the last position in the array. Alternatively, you could play with Append to array and transpose array to reach a similar result.

Remember that if you have to use large arrays, these solutions will result in slow execution speed, since they are strongly memory inefficient : at each iteration (at each new addition), a new array has to be created. If this is the case, you should use Initialize array to create an array with a size equal to the final size, filling it with NaN values (only for floatting point number), and then use the replace element function to input your data in the array.

 

Edit : OK Christian, this time you have been faster... 😄
Message Edité par chilly charly le 01-09-2009 05:18 PM
Chilly Charly    (aka CC)
Message 6 of 11
(62,976 Views)

I don't follow the answer. I want an array that can be 1 to 8 rows and 100 columns. I ahve a 1 d array of 1 row with 4 coulmns that change over and over. This is taken from a DAQms read 1d waveform and ran through a queue and is still 1d of waveform. I am going to save this data to file but I want the different channels of data read to be in a table format with a row for each channel and a column for each sample. This can be up to 8 rows of data that will have an new point in the column every time time a read is performed. The number of samples is a variable and is the number of columns I want. So the array size can be the rows and the columns needed will be the number of samples (which is a control). 

The 1d array (what I have now) of (4 channels of data) with 100 sample taken yields

 r1,r2,r3,r4 whose values change every DAQmx read.

 

I need to get to

r1,r1,r1,r1.........to 99

r2,r2,r2,r2.........to 99

r3,r3,r3,r3.........to 99

r4,r4,r4,r4.........to 99

whose values change each time a DAQmx read is taken.

0 Kudos
Message 7 of 11
(62,932 Views)
Here is an example for DAQmx 9172. The conversion needs to be in the queue section.
0 Kudos
Message 8 of 11
(62,927 Views)

Thanks altenbach,

I went back and tried your example again and it seems to work. I will only use this to save data to a file.

0 Kudos
Message 9 of 11
(62,889 Views)

Greetings,

 

I have a similar problem as to the original one I posted. I did try searching the forums and initially pointed me in the right direction, but I've hit a snaffu. First things first, I'm dealing with Windows XP and V8.5 Labview.

 

My problem is the string array I'm reading in is not symmetric by nature, which quite frankly is what I'm use to. So in regards to parsing and indexing this has come as a challenge to me. Basically the 1D array is (mostly) formatted as follows.....

 

SN

"empty"

"header info really not needed"

FREQ

AMPLITUDE

"empty"

 

(repeats for n amount of times)

 

The caveat I'm dealing with is as follows....

 

SN

SN

SN

"empty"

"empty"

FREQ

AMPLITUDE

"empty"

 

This happens a few times throughout the file. I know it's not ideal and quite frankly needs to be fixed at a lower level, but this is what I have to deal with in the interim. I've supplied my VI, and you will be able to see how this causes a "shift". Now the good part is I know exactly where and why my shift is happening, but cannot get in the direction of a solution. My ideal final 2D array is as follows....

 

SN | empty | empty | FREQ | AMPLITUDE | empty

 

Any help would be much appreciated. This forum has always been great in my knowledge development of Labview. I'm sorry if I left anything out, please let me know. I'm also under the weather which is great for making the brain work 🙂

 

Cheers,

 

ChazzzMD

 

 

 

 

0 Kudos
Message 10 of 11
(60,687 Views)