LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to load a variable using MATLAB Script?

I need to load a selected variable from .mat file, using MATLAB script , and analyse it.

 

the attched shows my vi, there are two inputs nodes 'file' contains the .mat file path, and 'varn' contains varibale name in that .mat file which can be selected by user. Using " load(file)" the whole .mat file is loaded in the workspace and become avaiable at output node, however I am not able to pass a selected variable name through string "varn" input, MATLAB script does not recognize the variable.

any idea to reslove it is realy appreciated.

 

0 Kudos
Message 1 of 5
(4,849 Views)
Instead of a String Data Type, I used Path Data Type and was able to get it working in MATLAB Script node
Andy Chang
National Instruments
LabVIEW Control Design and Simulation
Message 2 of 5
(4,828 Views)

Andy,

 

I used Path data type to pass the variable's name , by converting string to path, however I recived error message 1050!, do I need to convert back Path to string?(please see the attched)

 Thanks,

 

 

0 Kudos
Message 3 of 5
(4,787 Views)
Download the VI and .MAT file. Run the VI, and it'll plot the data inside of the .MAT file.
Andy Chang
National Instruments
LabVIEW Control Design and Simulation
0 Kudos
Message 4 of 5
(4,759 Views)

Thanks for the reply Andy,

 

My code is able to load the *.mat file but not able to pass a selected variable's name to the Matlab Script , here is an example:

 

assume in *.mat file , testfile.mat that you sent, there are V-char1, V-char2,V-char3,....., and V-char100, now using a Enum in front panel the user should be able to select one variable  name at a time , for example V-char50, and plot it.

in my code "varn" input node is supposed  to do this job.

after loading the *.mat file " load(file)" when I typed the variable name directly " plot(V-char50) it works , but if I select " V-char50" from front panel and pass it through "varn" input does not recognize the varaible's name .

 

0 Kudos
Message 5 of 5
(4,743 Views)