Stand alone application using MATLAB compiler doesnt start if images are loaded in OpeningFcn
5 views (last 30 days)
Show older comments
The application is a GUIDE GUI and when compiled using the MATLAB Compiler works only if the OpeningFcn doesn't contain loading images. Certainly I doing something wrong in this function. If I cant use the image command in this function is there any other way I could load images when the application starts.
function WSM_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to WSM (see VARARGIN)
% Choose default command line output for WSM
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% Center the GUI
movegui(handles.WSM, 'center');
% Load the Logo
logo = imread('logo200.png');
image(logo, 'Parent', handles.logo1)
axis(handles.logo1, 'off')
% Create image buttons
g = importdata('file_new32.jpg');
set(handles.newFile,'CDATA',g);
g = importdata('file_open32.jpg');
set(handles.openFile,'CDATA',g);
g = importdata('file_save32.jpg');
set(handles.saveFile,'CDATA',g);
g = importdata('data_imp32.jpg');
set(handles.impWizard,'CDATA',g);
g = importdata('doc_prop32.jpg');
set(handles.viewLog,'CDATA',g);
g = importdata('doc_prop_clicked32.jpg');
set(handles.hideLog,'CDATA',g);
set(handles.tab1, 'Value', 1);
0 Comments
Answers (3)
Judy Zouaoui
on 28 Jun 2017
Edited: Walter Roberson
on 28 Jun 2017
I got the same problem and I use also imread(). I had an error sound when I wanted to load my image from my standalone application. I finally find the problem. To load the file, the standalone application need the whole path if the file is not in the same folder. Matlab code :
[filename pathname] = uigetfile({'*.png';'*.tiff';'*.jpg'},'File Select');
Image = imread(filename);
--> Error sound;
Image = imread([pathname,filename]);
--> OK
1 Comment
Walter Roberson
on 28 Jun 2017
Note: I recommend you use fullfile() instead of concatenating the strings. uigetfile() does not promise that the pathname will have a directory separator at the end.
Walter Roberson
on 2 Sep 2011
What behavior do you see instead of it working?
Is there a reason you are using importdata() instead of imread() for those .jpg files?
2 Comments
Walter Roberson
on 2 Sep 2011
Perhaps you should add a try/catch block.
What directory do you expect that the executable will start in? Have you changed directories before you read in the files? I think I read that in Windows, the current directory at the start of a GUI execution is the directory that the executable is stored in.
You may need to use deploytool to "-a" (add) those images to your CTF, and then to pull them out of the temporary directory that your GUI expands in to. You can retrieve that name as the environment variable MCR_CACHE_ROOT; see http://www.mathworks.com/help/toolbox/compiler/brl4_f1-1.html
Slamdunker23
on 7 Jul 2015
Hello. I have exactly the same problem. I also use imread() to load an image into my GUI before starting the GUI.
Did you ever solve that problem?
Thanks in advance,
Daniel
0 Comments
See Also
Categories
Find more on Environment and Settings 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!