09-24-2013 07:59 AM
Dear all,
I am having trouble solving a little part of matlab script in labview. I am multiplying two arrays ( a 2D with 1D) inside mathscript but it generates an error of input matrices incompatibilty. The sizes of the input matrices are incompatible. Verify that the matrices have the same size or that one is a scalar.
I have tried executing same code in MATLAB and it generates no error; gives me the correct values. The code is
projected_test_image = eigenfaces'.*normalized_test_image;
Why is my labview not solving this while matlab does? Help needed
Regards
09-24-2013 08:29 AM
Hi,
attaching VI could help. Do you have the right dimension of matrix and vector?
Simyfren
09-24-2013 08:42 AM
Hello NapDynamite,
Likely what is happening is that your 1D array is of the wrong orientation. LabVIEW does not differentiate between a row vector and a column vector. Thus, MathScript must make a decision when it inputs a 1D array. It happens to choose a row vector. But even if it chose a column vector, it's wrong half the time. Thus, in your code, you are multiplying a 2D array with a row vector. This isn't allowed. Try transforming your normalized_test_image vector in your MathScript node.
See the second-to-last paragraph for reference: http://zone.ni.com/reference/en-XX/help/371361J-01/lvconcepts/scriptnodes/
Grant M.
Senior Software Engineer | LabVIEW Tablets | National Instruments
09-24-2013 09:25 AM
Dear GrantM,
I tried doing same thing by labview nodes ( transpose array and then cross-product). Now comes another situation which I couldn't just figure out. I have another matlab node as follows. I have converted each array into matrix, fed it to script inputs and it's running but not giving correct values. Before this node, I have cross checked every loop with matlab data and they are correct. But at this point the value is not correct ( Euc_dist_min ).
Do I need to change something in the script? Can you please point out?
Regards.
09-24-2013 09:45 AM
OR
How can I perform same operation using LabVIEW functions ( for loop, vector norm function but don't havt quite an idea ). I need to match the result from original .m script running in matlab for verification.
Regards.
09-24-2013 04:04 PM
Hello NapDynamite,
Converting the 1D array into a 2D array before giving it to the MathScript node is another workaround. However, it may be simpler to avoid the 2D array and just transpose the 1D array on the first line:
normalized_test_image = normalized_test_image.';
You want to use the array transpose operator (.') to avoid calculating the Hermitian transpose ('). Although, if your values are all real, the two are identical.
As for performing the same operations in LabVIEW, the help for the norm function gives some implementation details. The default case computes the Euclidean (or l2) norm. For a vector [a b c], it is equivalently calculated by
vector_norm = sqrt(a^2 + b^2 + c^2);
Since you are squaring the result of your norm calculation, note that you no longer have the Euclidean distance.
Grant M.
Senior Software Engineer | LabVIEW Tablets | National Instruments
08-13-2019 06:12 PM - edited 08-13-2019 06:17 PM
Can you guys help me with a similar problem?
I'm working with a discrete PID and I noticed that the error is in the vector xk1 so I tried to transpose it but it doesn't work either. The error suggests an incompatibility of dimensions. I read somewhere else that labview reads and displays arrays as column vectors in 2-D array real (which is the type of data that belongs xk output), while in mathscript the arrays are read as matlab code. As I said, even transposing the vectors I can't get to multiply A*xk1.
P.d. Error:
Error 1050 occurred at LabVIEW: (Hex 0x441) Error occurred while executing script. Error message from server: ??? Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.*'.
08-14-2019 02:01 AM
08-14-2019 02:12 AM
Because that's the only way to get xk and generate the output "y" for the system when working in space-state. Please, help me out with a solution..
08-14-2019 02:48 AM