LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Combine 2D String Array Rows, when 1 value is similar

Hi guys, I have been struggling trying to combine rows with a single like element in them...... for instance an Array that is like:

 

[A, B, C, D],

[E, F, G, H],

[I, J, K, L],
[M, N, O, D]

 

 

Should then become:

 

[A, B, C, D, M, N, O, D],

[E, F, G, H, , , , ],

[I, J, K, L, , , , ]

0 Kudos
Message 1 of 5
(154 Views)

Hi HSG,

 


@HSG16 wrote:

Hi guys, I have been struggling trying to combine rows with a single like element in them......


What have you tried and where are you stuck?

 


@HSG16 wrote:

Array that is like:

[A, B, C, D],

[E, F, G, H],

[I, J, K, L],
[M, N, O, D]

 

Should then become:

[A, B, C, D, M, N, O, D],

[E, F, G, H, , , , ],

[I, J, K, L, , , , ]


  1. Index the 1st and 4th row and create one 1D array from them by using BuildArray in "concatenate" mode.
  2. Index the 2nd and 3r row from input array.
  3. Use BuildArray with the longer 1D array from step 1 and the 2 arrays from step 2.

Done.

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(138 Views)

Hello @GerdW

 

I have made a few attempts all leading to failure over the course of a week and I wish I had something to show for them but they have all been try and delete and retry and delete. I think the problem comes in where the goal is to make this dynamic so regardless of Array Size and regardless of how many duplicates are in the array, each item appears on one row. I have gone the route where I ended up with 4 nested For loops and at that point, I had to stop. 

0 Kudos
Message 3 of 5
(123 Views)

Hi HSG,

 


@HSG16 wrote:

I think the problem comes in where the goal is to make this dynamic so regardless of Array Size and regardless of how many duplicates are in the array, each item appears on one row.


You didn't mention this requirement in your first message.

Describing a problem correctly really helps to solve the problem…

 

  1. Get the 1st row of the array.
  2. Check if there are duplicates in the next row
  3. when there are duplicates: combine the rows and go to step 2
  4. when there are no duplicate: go back to step 2 until you reach the last row
  5. go back to step 1 and proceed with the next row until you reach the last row

@HSG16 wrote:

I have gone the route where I ended up with 4 nested For loops and at that point, I had to stop. 


From my quick description it seems you need just two stacked loops…

 

Is this just homework to learn (array handling in) LabVIEW or is there a real-world problem to solve?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 5
(111 Views)

@HSG16 wrote:

Hi guys, I have been struggling trying to combine rows with a single like element in them...... for instance an Array that is like:



@HSG16 wrote:

I have made a few attempts all leading to failure over the course of a week and I wish I had something to show for them but they have all been try and delete and retry and delete. I think the problem comes in where the goal is to make this dynamic so regardless of Array Size and regardless of how many duplicates are in the array, each item appears on one row. 


 

 

Do you have more detailed requirements? What should happen if there is more than a single like element?

 

Arrays are always rectangular, so you need to pad short rows. What's the padding element?

What are possible "elements"? All single uppercase letters or can there be longer words?

What should happen if an element occurs in more than two rows?

What should happen if multiple elements in one row match with element in several other rows?

What determines the order of appending?

Does the order of elements in each row need to be maintained?

What is an Item? (single element?, original row?)

0 Kudos
Message 5 of 5
(92 Views)