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

5 次查看(过去 30 天)
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);

回答(3 个)

Judy Zouaoui
Judy Zouaoui 2017-6-28
编辑:Walter Roberson 2017-6-28
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 个评论
Walter Roberson
Walter Roberson 2017-6-28
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
Walter Roberson 2011-9-2
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 个评论
salamay
salamay 2011-9-2
"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 2011-9-2
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
Slamdunker23 2015-7-7
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

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by