using .mat and .m files in GUI

18 views (last 30 days)
miner
miner on 16 Aug 2011
Background: I am building a GUI which uses uigetfile to allow user to select .mat file containing data of interest. The .mat file contains some matrices, from which the GUI will select one with a certain name and pass it to a function outside the GUI.
My question: How can I get the GUI to pass the matrix of interest from a .mat file that the user selects to an outside function? I began by finding the handles of the outside function by
functionhandle=@function;
[output]=functionhandle(matrix from .mat file, etc.);
Thanks

Answers (2)

Walter Roberson
Walter Roberson on 16 Aug 2011

Fangjun Jiang
Fangjun Jiang on 16 Aug 2011
a=load('datafile.mat');
VarName=fieldnames(a);
will give you all the variable names in datafile.mat. Then, select a variable name and pass the value to your function.
MyVarName=VarName{1};
functionhandle(a.(MyVarName))

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!