Stand alone application using MATLAB compiler doesnt start if images are loaded in OpeningFcn

5 views (last 30 days)
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);

Answers (3)

Judy Zouaoui
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
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.

Sign in to comment.


Walter Roberson
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
salamay
salamay on 2 Sep 2011
"What behavior do you see instead of it working?"
The code works without any problem when running the source from MATLAB
When i run the compiled application on another PC with the MATLAB runtime it just doesnt start and I get an error sound. I dont know what that error is. But if I remove these image statements the application runs fine with the runtime.
"Is there a reason you are using importdata() instead of imread() for those .jpg files?"
There is none. I could use imread instead of importdata but thats not the problem.
Could it be that its not able to find tose images on the drive?
Walter Roberson
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

Sign in to comment.


Slamdunker23
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

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!