MATLAB Answers

Edward P

How to load .mat into GUI

Asked by Edward P
on 8 Nov 2011

Hi everyone, It occurs an error that i can't understand why.

%load button
   function pushbutton3_Callback(hObject, eventdata, handles)
  % hObject    handle to pushbutton3 (see GCBO)
  % eventdata  reserved - to be defined in a future version of MATLAB
  % handles    structure with handles and user data (see GUIDATA)
[filename,pathname] = uigetfile({'*.mat';'*.*'}, 'Load');
file_load = fullfile(pathname,filename);
guidata(hObject, handles);

the error is:

??? Error using ==> imshow>validateParent at 307
HAX must be a valid axes handle.
Error in ==> imshow at 221
Error in ==> tent>pushbutton3_Callback at 102
Error in ==> gui_mainfcn at 96
Error in ==> tent at 43
    gui_mainfcn(gui_State, varargin{:});
Error in ==>
??? Error while evaluating uicontrol Callback 

What i have made wrong? I believe that my workspace is successfully loaded.



No products are associated with this question.

3 Answers

Answer by Titus Edelhofer
on 9 Nov 2011
 Accepted answer

Hi Edward,

hmm, you load the handles? That will probably fail because each time you start your GUI, handles.axes3 and handles.axes4 will be different. I would do the following instead

im = load(file_load);
handles.D = im.handles.D;
handles.E = im.handles.E;

This way you leave your (other) handles untouched ...


  1 Comment

Edward P
on 9 Nov 2011

You were right! thanks! It really works now!

Answer by Titus Edelhofer
on 8 Nov 2011


hmm, I am wondering why it is


in the error message but


in the code. But apart from that: what variable do you read from the .mat file? And where do you use it? I can't see it in the code ...


  1 Comment

Edward P
on 8 Nov 2011

My fault! i used image1 to make easier to understand.
The point is:load some images (E and D) that i've once invoked to my program, and plot those images on axes3 and axes4. This plot is correct because i've have already used this code.

Answer by Naz
on 8 Nov 2011


Edward P
on 8 Nov 2011

load(file_load), loads my handles already.

on 8 Nov 2011

hm... this should work. And you are sure you have your axes tagged as axes3 and axes4?

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!