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.
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.
06-21-2011 11:48 AM
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
Solved! Go to Solution.
06-21-2011 12:07 PM
06-21-2011 12:15 PM
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?
06-21-2011 12:21 PM
06-21-2011 12:39 PM
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.
06-21-2011 12:58 PM - edited 06-21-2011 12:59 PM
Do you actually want a 2-D array, where the length of one dimension is 1, and the other dimension is N?
06-21-2011 01:05 PM
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.
06-21-2011 01:39 PM
try e.g. a=b'*c or a=b*c' in the first line (note the single quote), depending on what you want...
06-21-2011 02:14 PM
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?!
06-21-2011 04:11 PM
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.