LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Make 2D array from 1D array

Solved!
Go to solution

Hi,

 

I have a 1D array and I would like to make a 2D array from it in the following order

 

1D array:  1 2 3 4 5 6 7 8 9 10 11 12

 

if Rows=4 then the 2 D array shoudl look like this           

 

1   5   9  

2   6   10

3   7   11

4   8    12

 

and if Rows=3

 

1   4   7   10

2   5   8    11

3   6   9    12

 

Could you please let me know how cna I do it in LabVIEW?  , Row number and 1D array are the input parameters

 

Thanks

0 Kudos
Message 1 of 9
(1,326 Views)

Reshape Array.

 

You may or may not need to use a Transpose Array after that.

0 Kudos
Message 2 of 9
(1,323 Views)

And what should happen if the number of array elements is not divisible by the number of rows (pad with zeroes? truncate?)


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 3 of 9
(1,312 Views)

Thanks OrioleFan

 

Are you sure Reshape array will do that?

 

because if I pass the 1D array and 3 for row to this function it will output     ..  rows dimention =3   column=4

 

1 2 3 4 5 6 7 8 9 10 11 12

it will pass

 

1  2  3  4

5  6  7  8

9 10 11 12

 

but what I expect is this

 

1 4 7 10

2 5 8 11

3 6 9 12

 

 

 

0 Kudos
Message 4 of 9
(1,309 Views)

Hi althebach

 

It is always divisible. 

0 Kudos
Message 5 of 9
(1,304 Views)

To give anything that handles that task well requires an answer to altenbach.

 

You're going to end up wanting to use loops of some type and building your array.  But, you need to know how to handle that corner case.  What do you do if the number of rows s 5?

0 Kudos
Message 6 of 9
(1,299 Views)
Highlighted
Solution
Accepted by topic author tintin_99
08-27-2015 04:09 PM

As OriolesFan already said, reshape array is the correct function.

 

Here is the more general solution that pads the output array. if the elements are alway evenly divisible, you can leave out the "sign" and "add" function and just wire the IQ output to the upper size terminal of "reshape array". (and generate an error if the remainder output is not zero Smiley Wink)

 

 


LabVIEW Champion Do more with less code and in less time
Message 7 of 9
(1,297 Views)

Your solution was given by the first response - you do need to use transpose array.  If you take a twelve element array and reshape to three rows by four columns, this happens

 

1 2 3 4 5 6 7 8 9 10 11 12

 

goes to

 

1   2   3   4

5   6   7   8

9 10 11 12

 

This is not what you want. However, if you reshape to four rows and three columns, you get

 

  1   2   3

  4   5   6

  7   8   9

10 11 12

 

Which is still not what you want, but a Transpose then produces

 

1 4 7 10

2 5 8 11

3 6  9 12

 

which is exactly what you want.

This account is no longer active. Contact ShadesOfGray for current posts and information.
Message 8 of 9
(1,236 Views)

Thanks Altenbach.  I took your code and made it a polymorphic supporting 20 different data types, and added a few more features, and posted it over on LAVA.

 

https://lavag.org/topic/16226-new-array-vi/page-2#entry113339


Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
Interesting in learning all you can about automotive CAN bus communication? Checkout my 12 part CAN Blog series.
Checkout and help contribute to the community driven LabVIEW Wiki.

Message 9 of 9
(848 Views)