NI Home > Community > NI Discussion Forums

LabVIEW

Reply
Member
shimbloo
Posts: 46
0 Kudos

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.

 

Active Participant
Andy_C.
Posts: 370

Re: how to load a variable using MATLAB Script?

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
Member
shimbloo
Posts: 46
0 Kudos

Re: how to load a variable using MATLAB Script?

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,

 

 

Active Participant
Andy_C.
Posts: 370
0 Kudos

Re: how to load a variable using MATLAB Script?

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
Member
shimbloo
Posts: 46
0 Kudos

Re: how to load a variable using MATLAB Script?

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 .