LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Copying Data from 1D array to 2D Array

Solved!
Go to solution

Hi,

 

I am basically comparing strings from a 1-D array for a match. I have my matching results already.

 

I would like to create a new 2-D array and reshuffle the strings from the 1-D array to a 2-D array and populate the corresponding results, then output to a file along with the matching results. I would like to know the best approach for doing this. Please see the image as an illustration.

 

Thank you in advance.

 

2019-09-24_19-17-11.png

0 Kudos
Message 1 of 8
(3,055 Views)
Solution
Accepted by topic author LNH02

I think other Knight must have better solution but this is my idea.

 

FP.png

 

BD.png

 

Certified LabVIEW Developer
There are only two ways to tell somebody thanks: Kudos and Marked Solutions

GCentral
0 Kudos
Message 2 of 8
(3,025 Views)
Solution
Accepted by topic author LNH02

You have two (different) things to do.  One is to take your 1 x 8 (1 row, 8 columns) that is really two 1 x 4 arrays concatenated into 1 x 8 and transform it into a 2 x 4 array.  Now, it's not quite the right "shape" (you really want, ultimately, a 4 x 2 array), but trust me, it's easier to delay a step here.  Your ultimate Array as an extra 4 (blank) entries.  Well, the easiest way to stick arrays together is to use "Build Array", which works with rows, so we'll make a row of 4, then stick the 2 x 4 array and add the 1 x 4, ending up with a 3 x 4.  Now all we need to do is to change it to a 4 x 3.

 

So go to the Array Palette and look for functions that do the following:

  • Allow you to change the shape of an Array (to go from 1 x 8 to 2 x 4).
  • Allow you to create (and initialize) an Array (to get the blank 1 x 4 "third row/column").
  • Allow you to "stick together" a 2 x 4 and a 1 x 4 array to get a 3 x 4 array.
  • Interchange rows and columns to change from 3 x 4 to 4 x 3.

I'm deliberately not posting the code to do these four things (though you should be able to figure it out from the words above descriptions) -- you'll learn much better if you "look it up" (read the Help for Functions that you think might be useful, and write some test routines to "test your assumptions") than if I (or someone else) just "gives you the answer".

 

Bob Schor

Message 3 of 8
(3,018 Views)

Thank you, Bob, for the suggestion. I would definitely try that, that is when I have the time.  I am picking up someone else’s work and need to have  it completed in three days.

 

I saw a similar posting that uses integers, but haven’t tried it yet. This should work for my application, right?

 

https://forums.ni.com/t5/LabVIEW/Make-2D-array-from-1D-array/td-p/3018927?profile.language=en

 

 

0 Kudos
Message 4 of 8
(3,012 Views)

Hi Emboar,

 

Thank you very much for the response. I will definitely try it and let you know how it goes.

0 Kudos
Message 5 of 8
(3,009 Views)

I don't think following Bob's careful walkthrough should take 3 days, so you should be fine. Read carefully what he wrote and then follow the instructions:


@Bob_Schor wrote:

... easiest way to stick arrays together is to use "Build Array", ...

 

So go to the Array Palette and look for functions that do the following:

  • Allow you to change the shape of an Array (to go from 1 x 8 to 2 x 4).
  • Allow you to create (and initialize) an Array (to get the blank 1 x 4 "third row/column").
  • Allow you to "stick together" a 2 x 4 and a 1 x 4 array to get a 3 x 4 array.
  • Interchange rows and columns to change from 3 x 4 to 4 x 3.

Regarding the last point, the operation to interchange the rows and columns of a 2D array or matrix has a specific name, commonly used in mathematics, computer programming, and in particular in this case, in LabVIEW's Arrays palette.

 

As to the creation of a blank 1x4 third row/column, you may just implement this with your comparison operator(s) of choice. The key point is to get an array of the appropriate size and data type to go with your inputs (1xN, where the element type is the same as what is compared).


GCentral
0 Kudos
Message 6 of 8
(2,995 Views)

Hi Bob,

 

Sorry for the delay in response. I was able to find time to go through your instructions. It worked. Thanks so much!

0 Kudos
Message 7 of 8
(2,940 Views)

Hi Emboar,

Sorry for the delay response. This also worked. Thank you.

 

 

0 Kudos
Message 8 of 8
(2,932 Views)