LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

converting a matrix into 1D array

hello every one:

I have a Matrix of size( 600(rows) x 2268(cols) ),how I convert it to 1D array ?

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

I'm answering this from a standpoint of many years experience with LabVIEW and minimal experience with LabVIEW NXG (but I'm going to fire up a copy of NXG and test that what makes sense in LabVIEW makes sense in NXG).

 

matrix is a 2D mathematical entity that has specific rules for arithmetic, one subtly different from a 2D array, but looking "similar".  There are functions to convert Matrix to Array, and Array to Matrix -- the point here is that "Array" always means 2D Array.

 

So you want to convert a Matrix to a 1D Array, which can be (probably) reworded in "How do you convert a 2D Array into a 1D Array?".  There are many ways, but two are called "Row Major" and "Column Major" -- Row Major lists all the elements of Row 1, followed by all the elements of Row 2, and so on until all the rows are done, while Column Major lists Column 1, Column 2, etc.  Two functions that will help you do this is "Reshape Array" (which works in Row Major order) and Transpose 2D Array (which if done first, effectively switches you to Column Major).

 

So I just opened NXG (which I find very confusing and hard to use).  I can find Matrix, I can find Array, but I cannot (so far) find the Matrix to Array function (aha, why don't I try QuickDrop?).  Hmm, can't find the function.

 

Suggestion -- NXG is still a "product in Development Mode", while LabVIEW is a mature, functioning product.  I'd suggest switching to LabVIEW unless you have a specific need for NXG (and are willing to live with its lacunae).

 

Bob Schor

0 Kudos
Message 2 of 6
(3,544 Views)

thanx a lot  

 

0 Kudos
Message 3 of 6
(3,524 Views)

A few cautions:

 

- You might think of a Matrix and a 2D Array as two names for the same thing.  LabVIEW doesn't.  There are a number of ways they get treated differently

 

- "Resize Matrix" will not do what you want, at least not in classic LabVIEW.  Do a simple test with a 2x5 Matrix and see.

 

- "Reshape Array" can.  Kinda.  But there are several little details to deal with and understand.

1. You'll need to convert from Matrix representation to a 2D Array in order to use "Reshape Array".   Use quick-drop to find the function named "Matrix to Array".

2. When you perform the reshape from 2D to 1D, values will populate the 1D Array in a Row-Major way.  (All elements from Row 0 first, then all elements from Row 1, then Row 2, etc.)    If this is *not* what you want, you'll need to transpose the 2D Array before reshaping it.

3. The 1D Array in LabVIEW is inherently neither a row vector nor a column vector.  It is just a 1D ordered arrangement.  You can choose to display it as if it were either a row or a column, but that will have no bearing on how the array *behaves* when used in computations.1

4. You can convert the 1D array to a column vector using "Array to Matrix".  Right click the function node on the block diagram, choose "Select Type...", and then choose "To Real Column Vector".

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 4 of 6
(3,515 Views)

@ASHLY19 wrote:


I'm going to repeat what I said before, which Kevin Price also pointed out:

  • A Matrix is not an Array!  A Matrix is a mathematical entity that has its own rules for how it works.  An Array, on the other hand, is a method to organize numbers to that you can access them using indices (hence Row Major or Column Major).
  • As Kevin points out, a 1D Array (in some languages called a "Vector"), in LabVIEW, doesn't distinguish between "row" and "column" (though some other Programming Languages make this distinction).
  • The fact that you are insisting on doing all of this leads me to suspect that you don't quite understand what you are doing.  It may be something as simple as not understanding the (mathematical) idea of a Matrix, and saying "Matrix" when you really mean "Array".
  • Without know more about what you are doing (or hoping to do), and without seeing all of your code, further help that will be useful to you may be difficult to provide.
  • Finally, I'll repeat that most of my comments (and, I suspect, of Kevin's) relate to LabVIEW (a.k.a. "Classic LabVIEW", currently LabVIEW 2019), not to LabVIEW NXG (currently LabVIEW NXG 3.1).

Bob Schor

0 Kudos
Message 5 of 6
(3,511 Views)

Use the function "Reshape Array"

André Manzolli

Mechanical Engineer
Certified LabVIEW Developer - CLD
LabVIEW Champion
Curitiba - PR - Brazil
0 Kudos
Message 6 of 6
(3,438 Views)