LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

extracting data columns from a 2D array using ids contained in a different 2D array

Hello
 
I would like to match id's contained in a 2D array (A) to the header id's (i.e. the first row labels of the 2D array) of a second 2D array (B) and extract the corresponding data columns from 2D array B.
 
So for example:
 
i have a 2D array (A) with 100 columns and 400 rows, where each cell contains a number from 0 - 300. These numbers are not in order and some will be repeated and some will not be there at all.
 
i have a second 2D array (B) with 300 columns and 400 rows, which contains my data.  For identification, the headers (labels) on the first row are numbered 1 - 300 in order.
 
So I want to use the numbers contained in my first 2D array (A), match them to the headers of my second 2D array (B) and subset the corresponding columns.
 
I hope that this is clear and that someone can help be.
 
Thank you and best wishes,
 
 
 
 
0 Kudos
Message 1 of 6
(3,575 Views)

Hi RVR,

This sounds like pretty straight-forward array handling, but a bit of clarification please!
 
> i have a 2D array (A) with 100 columns and 400 rows, where each cell contains a number from 0 - 300.
> These numbers are not in order and some will be repeated and some will not be there at all.
> i have a second 2D array (B) with 300 columns and 400 rows, which contains my data.
>  For identification, the headers (labels) on the first row are numbered 1 - 300 in order.
> So I want to use the numbers contained in my first 2D array (A), match them to the headers of my second 2D array (B)...
What should be dome when the value from array A is 0 ?
 
> and subset the corresponding columns.
It's not hard to pull-out a column of data from array B, but should this be done for every cell in A?  If so, where is this column going once extracted?
Should the solution build a 3D array of 100 by 400 (array A) by 400 (the depth of the column extracted from B)?
 
Cheers.
 
 
 
   
"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 2 of 6
(3,573 Views)

Hi

thanks for the response.  to answer your questions:

tbd> What should be done when the value from array A is 0 ?

rvr> when the value from array A is 0, then do nothing. there won't be a match with the header of array B as these range from 1 - 300. Similarly when the number from array A does not find a match on the header of array B, then do nothing as there won't be a match. So subset the column ONLY WHEN THERE IS A MATCH between the value of array A and the header of array B..

 

tbd> It's not hard to pull-out a column of data from array B, but should this be done for every cell in A? 

rvr> no. you only 'pull-out' the column of data from array B when its header (first row label) number is matched by the value from array A

 

tbd> If so, where is this column going once extracted?

rvr> the extracted columns should be put in a new 2d array (C)

 

tbd> Should the solution build a 3D array of 100 by 400 (array A) by 400 (the depth of the column extracted from B)?

rvr> no. the solution should build a 2D array with n columns and 400 rows. where n depends on the number of columns pulled-out from array B, (which will depend on how many matches were foudn between the values in array A and the headers (first row labels) of array B.

I hope this is clearer. Thanks for you r help.
0 Kudos
Message 3 of 6
(3,565 Views)

Hello,

I am attaching a vi containing a front panel explanation of what I want to do.

I appreaciate your help.

Regards,

0 Kudos
Message 4 of 6
(3,564 Views)

Hi RVR,

      Thanks, "what I want to do" was a big help and a nice starting-point for the attached VI.

Hope it helps!

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
Message 6 of 6
(3,541 Views)