how to load matfile through push button click in matlab GUI

4 views (last 30 days)
i am using code like below
[filename pathname]=uigetfile('*.mat',-mat)
x2=load(filename,'-mat);
evalin('base',x2);
problem here is that first 2 lines w/o x2= are executing in matlab command (only first 2 lines if i evaluated w/oGUI).then it is loading mat variables into matlab workspace. when i am executing through GUI pushbutton, only file name is loading into workspce instead of variables & also error was shown at evalin. error---undefined function or method evalin for i/p arguments of type cell,
any help will be apreciated
  1 Comment
Jan
Jan on 1 Jul 2014
I've formatted your code. Please care about a proper formatting - thanks.
The posted code has no valid Matlab syntax. Therefore we cannot guess its intention. What do you want to achieve by the "-mat" argument of uigetfile()?

Sign in to comment.

Answers (1)

Jan
Jan on 1 Jul 2014
Please read the documentation of evalin:
doc evalin
I assume you want this instead:
assignin('base', 'x2', x2);
  2 Comments
raj
raj on 2 Jul 2014
Hai, small correction , mistyped correctly,it is like this uigetfile({'*.mat','.mat') Through GUI also this one is working.i tried already assign command not working if i use assignin('base','x3',x2); one more variable with x3 is coming & that variable contains actual mat file(1X1 structure),its not loading MAT variables into workspace. any help how to load directly mat variables into workspace through GUI pushbutton
Jan
Jan on 6 Jul 2014
@raj: Sorry, I cannot follow your descriptions. Perhaps you want the indirect and error prone method:
evalin('base', sprintf('load(%s, ''-mat'')', filename));

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!