LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I run user-programmed Matlab functions in Labview?

Ok, I'm using a Matlab node in Labview, and I'm trying to run a function that I programmed.  For example:

[az,el] = thphi2azel(th,phi);

I have th and phi going into the Mathscript nodes as inputs.  I then try to take the outputs az and el and take them out of the mathscript node.  I get an Error 1048 when I do this and it says that el cannot be found.  I'm not using any pre-defined Matlab names.  I guess I'm wondering, is this even possible?  Or is there something else I'm doing wrong?  I have the m file for thphi2azel in the same directory as the vi. 

BTW, I'm running Labview 8.2.1 and Matlab 7.5.0 (R2007b).

Thanks,
Alan Stemmons
alanstem469@yahoo.com
0 Kudos
Message 1 of 4
(2,972 Views)
Hello Alan,

What you are trying to do is indeed possible.  The problem is that The MathWorks, Inc. MATLAB® software cannot find the function you have written.  The MATLAB script node operates as if you had run the script in the MATLAB software environment.  Try setting the path in the MATLAB script node to include the directory where your VI is located.  To make this work regardless of where on disk your VI is located, drop down the "Current VI's Path" primitive from the "Programming >> File I/O >> File Constants" palette.  Wire it to a "Strip Path" primitive from the "Programming >> File I/O" palette.  This will remove the VI's name from the path.  Wire this path into the MATLAB script node and then add that directory to your MATLAB search path with the "path" or "addpath" command.

The "MATLAB script node - Lorenz Diff Eq.vi" example from <LabVIEW>\examples\scriptnode\Differential Equation.llb shows a similar example of creating a path to use for the MATLAB script node.

MATLAB® is a registered trademark of The MathWorks, Inc.

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments
0 Kudos
Message 2 of 4
(2,959 Views)
Ok, thanks.  I'm kind of embarrassed that I didn't think of that before.

Now it's running, but I'm having a different problem.  Basically, I set up controls to change the inputs, and then I have indicators coming out from the outputs just so I could test the functionality.  However, when I run it, it just ends up having the same values on the indicators no matter what the controls are set at.  The indicators show 90, which is the outputs for the function if the inputs are 0, so I'm assuming that the inputs probably aren't actually getting into the function.  Any ideas?

Thanks
Alan Stemmons
0 Kudos
Message 3 of 4
(2,951 Views)
This is generally an indication of a problem in the script.  The input data is likely getting to the node, but the script fails somewhere during execution.  Consequently, the output variables are not updated.  When the node finishes, it reads the values of the variables which are still set to the values from the last successful execution.  Errors of this type are not reported very well by the script node.  Try running your script directly in The MathWorks, Inc. MATLAB® software in order to debug it with the values you specified.

MATLAB® is a registered trademark of The MathWorks, Inc.

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments
0 Kudos
Message 4 of 4
(2,949 Views)