LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Mathscript file

Is there any way to programatically import a mathscript from a file? I see I can import and export interactively, but I would like to have a VI that reads a mathscript from a file, runs it, and then outputs a waveform. This way people without Labview would be able to edit the script after deployment.

 

I realize that inputs and outputs will need to be the same. I'd just like to be able to programatically import and export the stuff inside the math script.

--

Brian Rose
0 Kudos
Message 1 of 6
(2,599 Views)
Hello Brian,

The basic principle you are talking about is simply using a user-defined function.  By placing your commands in a .m file and locating it within the MathScript search path, you can call the function simply by using the function name.  LabVIEW will detect when the file changes and update the generated code accordingly.  If you truly desire to replace the text in the MathScirpt node, see the Programmatically change text in a MathScript Node thread.

Note that both of these options require that the LabVIEW development system be installed on your system.  At this time, it is not possible to change a .m file in the run-time engine (a built application) or when deployed to an RT system.

Grant M.
Senior Software Engineer | LabVIEW MathScript | National Instruments
0 Kudos
Message 2 of 6
(2,572 Views)

I have basically the same problem, I would like the user to be able to choose a m-file he wants to run.

 

Is it possible to set the Mathscript search path programatically ? Or does e have to set it manually via Tools>Options>Mathscript in order to run the desired m-file.

 

One more thing, is it possible to run a m-file which is not a function ? In fact I have a lot of parameters set in the m-file, it is not very convenient to put all these parameters as outputs of the functions.

0 Kudos
Message 3 of 6
(2,393 Views)

kurisu,

 

As of right now tI know of no way to bypass the Tools>Options>Mathscript path. However it maybe possible to load multiple .m files and then use a path constant in LabVIEW to select the location of that .m file stored on the computer. 🙂 you may want to post that idea on the idea exchange http://forums.ni.com/t5/LabVIEW-Idea-Exchange/idb-p/labviewideas

Sam S
Applications Engineer
National Instruments
0 Kudos
Message 4 of 6
(2,372 Views)

Hello Kurisu,

 

It is possible to set the search path programatically using the addpath('c:/') function as described here: 

http://zone.ni.com/reference/en-XX/help/371361G-01/lvtextmath/msfunc_addpath/

 

However, this will only work for that one particular MathScript Node and its .m files and while the VI is running. Additionally, it will put the MathScript Node in reduced performance mode which could significantly slow the operations you are trying to perform. Finally, this function isnt supported in the LabVIEW run-time engine so you shouldnt use it in a stand-alone application or a shared library. Why are you unable to set the search paths statically? Is there no way to know the location of your files before runtime?

 

As far as your other question - yes it is possible to run an m-file which is not a function but it will also put your MathScript Node into the reduced perfomance mode since MathScript will be unable to determine the inputs and outputs your script consumes.

 

Cheers!

 

K Scott 

Message 5 of 6
(2,368 Views)

Thank you for your reply.

 

It worked well with addpath. In fact, I just wanted the user to choose the m-file to run so I don't know the path before running the VI. It is a parameter m-file. Maybe it is not the ;ost efficient way to do it, but since I am totally new to LabVIEW, I don't know any better way. 

0 Kudos
Message 6 of 6
(2,359 Views)