LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to move some elements from a 2D array to another 2D array?

I have a 2D array (many rows, 3 columns to be more specific). Is there a way I can look through column one for one specific word, and then take all the rows that correspond with that one word from column one and place them into a different 2D array?

 

Example:

 

Trucks     Ford     Silver

Cars        Chevy    White

Cars        Toyota     Red

Cars       Nissan      Blue

Vans       Toyota    Purple

 

I want to take anything that has "Cars" in the first column, take that whole row that corresponds, and place it into its own array.

0 Kudos
Message 1 of 5
(967 Views)

Hi learning,

 


@LearningLabVIEW wrote:

Is there a way I can look through column one for one specific word, and then take all the rows that correspond with that one word from column one and place them into a different 2D array?


Yes!

Use a for loop to autoindex the rows. Inside the loop check the first element of the row and keep all rows starting with cars. Learn about conditional output tunnels of loops...

Best regards,
GerdW


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

How would LabVIEW know to grab the whole row?

0 Kudos
Message 3 of 5
(948 Views)

@LearningLabVIEW wrote:

How would LabVIEW know to grab the whole row?


If you use index array on a 2D array, you have several options as explained in the help.

 

  • If you wire both index inputs, you get a single element as scalar.
  • If you leave the bottom index disconnected, you get the row as wired to the top index as 1D array.
  • If you leave the top index disconnected, you get the column as wired to the bottom index as 1D array.
  • If you leave both unwired, you get the first row.
  • etc.

And yes, if you autoindex on a loop boundary you reduce the number of dimension with every autoindexing  tunnel.

 

In your case you would get one row with each iteration where you can use an index array to inspect the first element, then decide based on its value. All basic stuff. Did you do some tutorials?

0 Kudos
Message 4 of 5
(920 Views)

Hi Learning,

 


@LearningLabVIEW wrote:

How would LabVIEW know to grab the whole row?


It "knows" by using autoindexing on a 2D array…

 

Loops with autoindexing tunnels are a very basic LabVIEW concept. It is explained in those "Training resources", offered at the top of the LabVIEW board!

Best regards,
GerdW


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