*m file works but GUI doesn't. i don't get it ... :( please if some1 can help
1 view (last 30 days)
Show older comments
Hello,
I'm a student and I'm working on a program for my final exam.
The ideea of the program is to make anaglyph pictures.I have 2 buttons that open image files : 1 for left eye and 1 for the right eye and 2 axes to see the images in them.
The problem I have is that when I open my program's GUI from matlab (File->Open ) the program doesn't work properly (BUT when I run the program from the main *m file it works ok).The problem ocurs when i try to open an image file. This is the error that I get when I open the GUI :
??? Attempt to reference field of non-structure array.
Error in ==> Convertor3Dbeta>ImagineSt_Callback at 98
axes(handles.AxaImSt);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> Convertor3Dbeta at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)Convertor3Dbeta('ImagineSt_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
As the error point out the error is somewhere here:
function ImagineSt_Callback(hObject, eventdata, handles)
% hObject handle to ImagineSt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global imagine_st
global im_st
global i_st
imagine_st = uigetfile({'*.jpg;*.bmp'});
im_st=imread(imagine_st);
i_st=im_st;
axes(handles.AxaImSt);
imshow(imagine_st);
set(handles.AxaImSt,'Visible','Off')
The code is the same for both buttons Please if someone can help me. Thank you very much in advance.
PS : The program doesn't work either when i try to export it, using deploytool, as a windows application
0 Comments
Answers (1)
Walter Roberson
on 2 Jun 2011
You cannot just open the .fig file: you have to run the .m file. The .m file contains initialization for the .fig file.
We will need more information about what happens when you attempt to deploy the code.
2 Comments
Image Analyst
on 4 Jun 2011
Yes. You have to use fullfile(), exist(), and possibly uigetfile(). Basically you have to know what folder your images live in because assuming they are always in the current folder is not a good idea - ESPECIALLY when you're dealing with compiled applications, which is a whole other level of complication and confusion (see the FAQ). For that reason you have to build up your full filename (folder + base file name) and then check if it exists with exist(fullFileName, 'file') so you don't throw an exception. Warn user it doesn't exist with warndlg().
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!