I would like to dynamically load a Matlab .m file into the Matlab Script function in a VI.
In other words, based upon a path to a .m file (control on the FP), load the .m file into the Matlab Script and then execute it.
Does anyone know how to do this?
Solved! Go to Solution.
It's not possible to do what you're asking. However, I can think of a couple options that will give you the same behavior.
1. If you only have a few of your .m files that will be called you can use a case structure with these files already loaded. The user can then choose which case to run.
2. You can have the Matlab Script Node run you particular .m file based on an input (number maybe), but this does also require you to have a predefined list of your .m files.
Thanks for the suggestions.
A coworker suggested dynamically loading a VI from a specific location. With a simple edit to the VI (new .m file) an application could dynamically load the VI and run the new .m file.
I have not yet written the code.
However, there is not much to it. Use the "Open VI Reference" function that has a path to your VI with the Matlab Script in it. The VI will have inputs and outputs (must always be the same no matter what VI you dyamically load) that match the inputs and outputs to the Matlab Script. After the VI has run, close the VI reference.
I would like to point out that the chosen solution by the National Instruments applications engineer is unfortunately not correct. There are at least two ways that this can be done.
Hopefully this helps anyone who comes across this page! If someone could please unmark the current solution as correct, that would be great as well.
What do I need to install to have MLApp.DIMLApp accessible? How to find this ActiveX Class in the browser?
I installed Matlab Runtime and I guess I found the proper file here:
C:\Program Files\MATLAB\MATLAB Runtime\v96\bin\win64\mlapp.tlb
I was unable to find it in the list populated in "Select Object From Type Library" window. I needed to browse and manually select the mentioned TLB file.
I even registered it running:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\regtlibv12.exe "C:\Program Files\MATLAB\MATLAB Runtime\v96\bin\win64\mlapp.tlb"
But I'm still getting error 3005 (no matter which Object I select).
How to fix the error and why Matlab lib need to be manually selected and registered?
This would be a good topic for a new forum post since the initial topic here has been answered.
Technical Support Engineering