Discussion:
Can I call a User-Defined Mathscript Function using LabVIEW 7.1?
(too old to reply)
labview_user
2008-08-12 15:10:08 UTC
Permalink
I am trying to use a User-Defined function call in a mathscript node using LabVIEW 7.1 and I cannot seem to make it work.
 
For example, consider that my mathscript node contains:
 
clear all;
close all;
x = linspace(1,100,5);
y = mltp(x);
 
where the labview vi is saved in the same folder as the mathlab script mltp.m that is given by:
 
function out1 = mltp(in1)
out1 = 5*in1;
 
Creating an array output of the mathscript node for y yields an empty array.
 
How can I use User-Defined functions in a mathscript node using LabVIEW 7.1?
 
 
smercurio_fc
2008-08-12 15:10:10 UTC
Permalink
Did you properly set your path? From the Help for saving scripts:You must save the function or script in a directory that you specified in the
Path section of the <a href="lvdialog.chm::/MathScript_Preferences_DB.html" target="_blank">MathScript Preferences</a>
dialog box. From the Mathscript Preferences Dialog Box Help:- Path?Sets the default search path list. LabVIEW searches
the path list from top to bottom to find functions or scripts that you defined
and want to execute in the LabVIEW MathScript Window. Use the
MathScript <a href="lvtextmath.chm::/MSfunc_path.html" target="_blank">path</a> function to
modify the search path list for the current instance of LabVIEW. LabVIEW resets
the search path list to the default when you restart LabVIEW.
GrantM
2008-08-12 15:40:21 UTC
Permalink
Hello,The MathScript node was not introduced until LabVIEW 8.0.&nbsp; Are you perhaps using the MATLAB script node?&nbsp; Unfortunately, there is not a search path section of the Options dialog like there is for the MathScript node.&nbsp; You will need to set the path explicitly.&nbsp; Instead of hard coding a path, take a look at the Lorenz equation shipping example to see how to set the path if you wish to locate the user-defined function .m file next to your VI: &lt;LabVIEW&gt;\examples\scriptnode\Differential Equation.llb\MATLAB Script - Lorenz Diff Eq.vi.&nbsp; Instead of using the "Default Directory" path primitive, you will want to use the "Current VI's Path" primitive from the File I/O &gt;&gt; File Constants palette.&nbsp; Then use the Strip Path primitive, convert it to a string, and pass the path to the MATLAB script node.MATLABĀ® is a registered trademark of The MathWorks, Inc.Grant M.Staff Software Engineer | LabVIEW Math &amp; Signal Processing | National Instruments
labview_user
2008-08-12 15:40:26 UTC
Permalink
Works like a charm.
&nbsp;
Thanks!

Loading...