LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Filling a 2-D array with a defined number of zeros per row

Solved!
Go to solution

Hi!

 

I have a 2-D array with m rows and n columns: ((x11,x12,x13,...,x1n),(x21,x22,x23,...,x2n),(x31,x32,x33,...,x3n),...,(xm1,xm2,xm3,...,xmn)), where xij means the element located in row i and column j, and xij is a real number.

 

I need to fill each row with a previously defined number of zeros per row and to the beginning of each row.  For example 5 zeros have to be  added to the beggining of the first row, two to the second row, 4 to the third row,...,6 to the last row:

 

 ((0,0,0,0,0,x11,x12,x13,...,x1n,0),(0,0,x21,x22,x23,...,x2n,0,0,0,0),(0,0,0,0,x31,x32,x33,...,x3n,0,0),...,(0,0,0,0,0,0,xm1,xm2,xm3,...,xmn))

 

I added zeros to the end to maintain row's lenghts equal between them

 

May you please help me with the code?

Message Edited by fgarcia on 01-30-2010 06:46 AM
0 Kudos
Message 1 of 6
(3,555 Views)

Hi fgarcia,

 

Is there allready data in the 2D array which you want to add the zeros in front of? Or is the array empty and you want to start adding data to it with a predefined number of zeros at the front of each row?

 

Steve.

0 Kudos
Message 2 of 6
(3,544 Views)

Hi Steve:

 

Yes, there is already data.

 

Thanks!

 

Francisco

0 Kudos
Message 3 of 6
(3,535 Views)
Solution
Accepted by topic author fgarcia

If you autoindex the 2D array and concatenate each row to a zero filled 1D array of defined lenght, then autoindex at the right boundary to again form a 2D array, the rows will be padded correctly automatically.

 

Here is some simple example code:

 

Message Edited by altenbach on 01-30-2010 08:16 AM
Download All
Message 4 of 6
(3,534 Views)

It works very well in my VI.  Thank you very much!Smiley Very Happy

Message Edited by fgarcia on 01-30-2010 11:01 AM
0 Kudos
Message 5 of 6
(3,521 Views)

The code shown is OK for occasional use and small arrays, but if you are dealing with very large data structures, you get a relatively large memory management penalty due to the constantly resizing data structures.

 

If performance is an issue, it would be better to calculate the final 2D array size beforehand, initialize it with all zeroes, and then replace elements with the old data rows at the correct offsets. It would not be much more complicated. Try it! 🙂

Message 6 of 6
(3,503 Views)