LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

Changing a path dynamically in a MathScript node

I have inherited a MatLab script that must be run in LabView. The first issue I have is creating unique paths. When a Unit Under Test runs, its data will be saved to a file based on the serial number of the UUT. The MatLab script then analyzes the data from that file and creates a new file based on the serial number with a new file extension. Therefore, I need to read in a file whose path changes and write a file whose path changes. The relative path will be the same but the unique file will not. I am looking for suggestions on how to do this since there will be hundreds of serial numbers being tested. It would be nice if the node could have an input that could configure to a path or string type instead of a scalar only. The serial numbers will be apha-numeric and this must be able to exist as a stand alone application.
 
Also, the node reports a 'unexpected token: function'. I am noticing that functions must be a seperate .m file but how do you call the function after that?
 
I am using LV 8.5
 
Thanks - Jeff


Message Edited by j.masse on 07-07-2008 07:57 AM
0 Kudos
Message 1 of 5
(7,491 Views)
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
Message 2 of 5
(7,481 Views)
Wonderful help  - Thanks
Another issue is that there is an unsupported function (unknown symbol) 'cell2mat'. Is there a way to rewrite this?
 
Data(Block,1)=cell2mat(InputText);
 
 
How can I rate your post? Jeff
 
In case you haven't figured it out yet, I am not a MatLab person.Smiley Sad


Message Edited by j.masse on 07-07-2008 12:15 PM
0 Kudos
Message 3 of 5
(7,478 Views)
Hello Jeff,

It is not just this function that will cause you a problem.  The cell2mat function presumably needs a cell array on which to work and MathScript does not support them.  If your InputText variable is being loaded from a file, the load command will likely return a run-time error.  Instead of creating a cell array in the first place, simply use separate variables for each cell in the cell array.  Then you will already have the matrix you need or you can easily create a larger one using matrix concatenation as shown in my last post.

As for rating a post, the bottom right of each message has a "Rate this message" selection.  Simply click one of the numbers.

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments
Message 4 of 5
(7,455 Views)
Thanks again for the help. As for the "Rate this Message", it does not appear on my screen but you get the best score. Thanks for your timely help.
0 Kudos
Message 5 of 5
(7,436 Views)