LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Combine two 1D arrays in one 2D array

Solved!
Go to solution

Hello everyone,

 

perhaps I overlook the obvious but I can't find a solution for combining two 1D arrays in one 2D array AND (that's the impossible part for me) using the arrays as columns instead of rows. 

 

Example: 

Array 1:    1, 2, 3, 4

Array 2:    5, 6, 7, 8

Result:      1, 5

                2, 6

                3, 7

                4, 8

 

The "build array" function seems to add all arrays as rows... I suppose I could transpose the array, but I want it to run in a sub-VI in different loop constructs and I feel a bit uncomfortable with that - I guess a would end up with a totally mixed array. Perhaps I was just to blind to find the right function?

 

Cheers, Jessi

0 Kudos
Message 1 of 4
(32,218 Views)
Solution
Accepted by topic author JessiFR

Hi Jessi,

 

by default LV is combining arrays by rows. So when you need columns you have to transpose the array(s) or use a different indexing scheme...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 4
(32,216 Views)

There is a saying " When something looks very simple, then May be you've misunderstood the point completely". I dont know if that is the case with me at the moment. But as far as ive understood your question. you need to ad up two 1-D arrays into one 2-D array. Moreover u need to add em up as a column. So for the first part u need to wire both ur arrays to the Build array block to get your 2-D array.

 

As far as adding them up in columns is concerned, u can do that by taking the transpose. and that should solve the problem. Provided if ive understood the problem the way ur encountering it.

 

Lastly the part about using the array as a Sub VI is concerned. May be i'll help if u state it a bit more objectively what is that you want to do. Cuz i dint get that part.

 

Have a ncie Day.

Regards
Asad Tirmizi
Design Engineer
Institute of Avionics and Aeronautics

" Its never too late to be, what u want to be"
Using LabVIEW 8.2
Message 3 of 4
(32,209 Views)

Thanks a lot. Seems like I have to transpose it, so I will just find a work-around for problems it may cause.

 

Concerning the sub-VI: I wanted to use the combined array in a loop-construct where other columns might be added - which would lead to the transposition of a transposed array and finally to lots of chaos 😉 I haven't programmed it yet, so it's still a bit whishy-washy... I will simply construct the final array after everthing else is finished, so I'm on the save side. I just wanted to see if there is a simple transpose-free solution. 

0 Kudos
Message 4 of 4
(32,195 Views)