LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

When are we supposed to transpose?

Hi!

 

Something that I'm always struggling to predict is when I am supposed to transpose an array ...

You have a nice 2D array made of rows and columns, index that in a for and you get .... well let's run it quickly ... ah rows.

 

My problem is also kinda extended to 1D arrays. When are they 2horizontal or Vertical? Does it even matter?

 

I've done this test right now (because I have to work with matrix and was not getting the expected result.

And, to me, it doesn't really make sense and I'm looking for one...

The "transpose 2D array" here is important... otherwise I get an array of only 1 element...

I enter a "vertical array", make a matrix out of it that considers it a column vector, put it back into a2D array, but if I don't transpose it before indexing, I just get the 1.

VinnyAstro_0-1676994840371.png

VinnyAstro_1-1676994994048.png

 

If anyone can explain to me the logic behind all this, I'd be grateful.

 

Thanks,

Vinny.

 

0 Kudos
Message 1 of 17
(1,554 Views)

Hi Vinny,

 


@VinnyAstro wrote:

if I don't transpose it before indexing, I just get the 1.

 

If anyone can explain to me the logic behind all this, I'd be grateful.


That's you fault! 🙂

 

  1. You are using IndexArray with its default input values: it will index the first row - which only contains one element "1". When you want to index the first column then you need to wire a "0" to the column input of IndexArray!
  2. Why do you convert a 1D array into a matrix which is defined as 2D structure in the first step?
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 17
(1,550 Views)

Well, array to matrix creates a column vector, so you have to transpose to get the original back. You can open it and look what it does.

If you were to use build array instead, all would be fine.

0 Kudos
Message 3 of 17
(1,532 Views)

Unlike in e.g. Matlab, "vectors" are simple 1D arrays and there is no concept of row- vs. column-vector. (no matter in what direction you resize it on the front panel!)

 

A "matrix" is a special typedef'd 2D array (guaranteed to be 2D, LabVIEW will silently substitute linear algebra for some basic operations)

 

If you look at all the LabVIEW tools in the linear algebra palette, they will typically operate correctly with a 1D array input for e.g. matrix/vector mixed operations. LabVIEW knows what to do!  So don't overcomplicate your code by artificially creating special vectors as matrix with one row or column. It does not matter!

 

In your above code, the compiler is actually smart enough to NOT actually rearrange the elements in memory and do a real transpose, but just flag the downstream code to swap indices instead.

 

Do you have any specific problem you are trying to solve?

Message 4 of 17
(1,507 Views)

Hi! And thanks for your replies!

 


@GerdW wrote:

That's you fault! 🙂


Never said it wasn't 😁

 


@GerdW wrote:

 

  1. You are using IndexArray with its default input values: it will index the first row - which only contains one element "1". When you want to index the first column then you need to wire a "0" to the column input of IndexArray!
  2. Why do you convert a 1D array into a matrix which is defined as 2D structure in the first step?

  1. So Labview indexes first by rows and then by columns. I've noticed that when I use for instance 2 for loops. The thing is I just never remember it and always have to test first. Is there a logic behind it or is it just a convention?
  2. I "suddenly" have to work with some transformation matrices and vectors, while my vectors are 1D arrays, my algebra is a bit far back and I wanted to do some test when I realized that I don't know if 1D arrays are row-vectors or column-vectors....

 


If you look at all the LabVIEW tools in the linear algebra palette, they will typically operate correctly with a 1D array input for e.g. matrix/vector mixed operations. LabVIEW knows what to do!  So don't overcomplicate your code by artificially creating special vectors as matrix with one row or column. It does not matter!

 

In your above code, the compiler is actually smart enough to NOT actually rearrange the elements in memory and do a real transpose, but just flag the downstream code to swap indices instead.

 

Do you have any specific problem you are trying to solve?


So if I want to apply a transformation matrix to a "1D array vector" I just multiply them?

As I said just above, in my application I have a lot of actual vectors (the Sun-Earth vector; The Nadir Vector etc.) in a specific coordinate system. And I have a VI that generates a transformation matrix from this specific system to another that I need my vectors into.

 

Up until now, 1D arrrays as vectors were fine, but just because of this transformation matrix I need to look into it 🙂

0 Kudos
Message 5 of 17
(1,449 Views)

Hi Vinny,

 


@VinnyAstro wrote:
  1. So Labview indexes first by rows and then by columns. I've noticed that when I use for instance 2 for loops. The thing is I just never remember it and always have to test first. Is there a logic behind it or is it just a convention?
  2. I "suddenly" have to work with some transformation matrices and vectors, while my vectors are 1D arrays, my algebra is a bit far back and I wanted to do some test when I realized that I don't know if 1D arrays are row-vectors or column-vectors....

  1. Read the help for the IndexArray function, it explains it very well in my opinion…
  2. As Christian wrote: 1D arrays are "vectors", there is no distinction on their "direction"… (Use the Algebra functions and don't forget to read their help.)
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 17
(1,443 Views)

I admit that I just look at the data and if it is coming out sideways, I suppose to transpose.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 7 of 17
(1,427 Views)

@billko wrote:

I admit that I just look at the data and if it is coming out sideways, I suppose to transpose.


That's generally my approach too. 😁

I tried a few times to remember the actual order and every time I needed it I was back at the 50/50 guessing game. So I figured why bother to learn that if I have to figure it out again anyhow. 😁

 

The specific problem here seem to be that the OP would like to have horizontal and vertical vectors. Which is an alien concept in LabVIEW. A vector is a vector is a vector. Rather than worrying about this part you have to make sure to apply a vector to the 2D matrix in the right way depending on the operation you want.

Rolf Kalbermatter
My Blog
Message 8 of 17
(1,414 Views)

I was annoyed by this a while ago, too.

For me, most of the time I generate Data from measurments, a 1D Array of Data.

In a while loop this results in a 2D Array. If you put this in a for loop, you get your 1D Array of Data out!

Most of the time I want to make a mean Array of that measured Data, to get the Data of one Sensor I have to transpose it. That's my approach to this, thinking about the generation of that data to know how to get what I want.

I never worked with matrix or vectors, just saying.

0 Kudos
Message 9 of 17
(1,394 Views)

@rolfk wrote:

The specific problem here seem to be that the OP would like to have horizontal and vertical vectors. Which is an alien concept in LabVIEW. A vector is a vector is a vector. Rather than worrying about this part you have to make sure to apply a vector to the 2D matrix in the right way depending on the operation you want.


Yep ok, I probably got too influenced with matlab some time ago and I never done any algebra in Labview.
And that's where my rusty algebra has to come back to life haha

0 Kudos
Message 10 of 17
(1,390 Views)