From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

array shape transposed?

Solved!
Go to solution

How can I find out what shape an array is within a long section of mathscript code? i.e is some array a row or column or matrix. I often get the error that the attached produces, regardless of what shape I expand the controls into.

 

I really need a definite way of determining the shape, rather than chucking transpose functions in randomly.

 

 

Thanks

 

0 Kudos
Message 1 of 12
(3,101 Views)
I am posting via phone so I cannot see yuor code, still .... The size if an array is independent from the size of the container. Ther is a dedicated mathscript forum that might be better suited.
0 Kudos
Message 2 of 12
(3,090 Views)

Defining a 1D array as having rows or columns is meaningless. Transposing a 1D array is meaningless. The visual representation on the front panel is just cosmetics. What exactly are you trying to do?

0 Kudos
Message 3 of 12
(3,082 Views)
I still haven't seen the code, but unlike LabVIEW, matlab syntax makes a distinction between row and column vectors. That could be part of the confusion.
0 Kudos
Message 4 of 12
(3,079 Views)

Christian, the code is just two identical 1 x n (or n x 1) arrays going into a mathscript node, with the code c=a*b, it generates

 

"Error -90011 occurred at Error in function * at line 2:  The sizes of the input matrices are incompatible.  Verify that the matrices have the same size or that one is a scalar."

 

For the equation to work I need to transpose one of the variables.

 

Dennis, this just illustrates the problem I keep facing in larger programs. I am doing a lot of vector maths and coordinate transformations, so this error appears frequently. I can use the transpose function in the mathscript to get things working, but generally I have no idea what shape variables are held inside mathscript.

0 Kudos
Message 5 of 12
(3,071 Views)

Do you actually want a 2-D array, where the length of one dimension is 1, and the other dimension is N?

 

0 Kudos
Message 6 of 12
(3,055 Views)

You should probably be using matrices with Mathscript and not arrays.  I have never touched Mathscript, but looking at your code and seeing that b'c gives you a 2D matrix leads me to believe that your 1D arrays are being treated as row vectors.  In your formulas I would just add the transpose operator (' I think) anytime you want a column vector.

0 Kudos
Message 7 of 12
(3,049 Views)

try e.g. a=b'*c or a=b*c' in the first line (note the single quote), depending on what you want...

0 Kudos
Message 8 of 12
(3,042 Views)

I'm not explaining myself very well. The code I posted just highlights the error that occurs.

 

If a=b*c, where b might be 3x3 and c might be 1x3

 

a=b'*c' is not equal to a=b*c'

 

I need to know how a and b are seen by mathscript (the shape of the arrays) in order to avoid accidentally transposing too many times, or transposing both variables. My real code is far larger and contains variables of various dimensions spread across about 10 mathscript nodes, so it's very difficult to keep track of the shapes, particularly when the shape of the input container makes no difference.

 

Am I missing something silly here?!

0 Kudos
Message 9 of 12
(3,032 Views)

As long as you are in LabVIEW, you can use the "array size" primitive to get the number of dimensions and the size in each dimensions. WIthin mathscript, you can use size command.

 

As in matlab, you need to know how your data is arranged in 2D arrays, because only you know what result you expect. Many array multiplications are not commutative. Within mathscript, this is a purely mathematical question. It has nothing to do with LabVIEW.

 

Your example program starts out with 1D arrays. As I said already, LabVIEW makes no distinction between row vectors and column vectors, so every 1D array wired to mathscript is a row vector (I think?). If you want to treat it as column vector, make it into a 1xN 2D array using "built array"  to mimic a row vector. Transpose it for a column vector (or simply add the single quote in the mathscript code).

 

Maybe I still do not fully understand your stumbling blocks. Can you show us a little more of your code? How complicated is it? Maybe it would be better to stay within pure LabVIEW functions. There is plenty in the linear algebra palette.

 

 

Message 10 of 12
(3,014 Views)