Hello Jeff,
Creating unique paths is not difficult in MathScript. Simply pass in the string you want to use as the specific part of the path and have a local variable contain the base path. For example, if you have a string input named
serial to the MathScript node, the following code will build a path:
basepath = 'c:\data\';
filename = [basepath serial];You mention needing to do this for a large number of files. The easiest way to do this is to have your loop in LabVIEW and simply pass in one string at a time to the MathScript node to do your processing. If there is a lot of setup work involved before the work that needs to be done for each file, then it is more complicated. There really isn't a concept of an array of strings in the language. The closest you can get is a cell array containing many 1D character arrays. However, LabVIEW MathScript does not yet support this construct.
You can pass in a LabVIEW 1D string array -- the MathScript node input will adapt to the type wired to it. What it does is create a 2D character array in MathScript. If not all the strings are the same length, then it will pad the end of the string with zeros. This presents a problem when you try to use the string as a filename. However, you can use the
strrep (string replace) function to replace the zeros with empty strings. For example, assuming you have an input variable named
serial that is a 1D array of strings and a loop-control variable named
index, type
basepath = 'c:\data\';
name = strrep(serial(index, : ), char(0), '');
filename = [basepath name];You cannot write a function inside of a MathScript node. What you can do is create a .m file on disk and add the directory to your MathScript search path. The default search path is your "My Documents\LabVIEW Data" directory. But if you add the file elsewhere, there are three ways to set the search path for MathScript. First, from the MathScript Window, go to "File >> LabVIEW MathScript Properties" and click on the "MathScript: Search Paths" category item. This will set the search path for the MathScript Window only. Second, from a LabVIEW VI, go to Tools >> Options and click on the "MathScript: Search Paths" category item. This will set the search path for all VIs in the main application instance only. Third, from within the project explorer, right-click on "My Computer" and select Properties. Then click on the "MathScript: Search Paths" category item. This will set the search path for that context only. Since you are talking about using this in a built application, the third option will likely be what you need.
As for using a built application generally, as long as you avoid any MathScript function that describes itself as being unsupported in the run-time engine, you should be okay. The help for individual functions will list if they are unsupported. You can see a list of all such functions by looking in the LabVIEW help index for "MathScript" and double-clicking on the entry for "functions not supported in Run-Time Engine."
Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments