Stand alone application using MATLAB compiler doesnt start if images are loaded in OpeningFcn
1 次查看(过去 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);
0 个评论
回答(3 个)
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
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
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 个评论
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
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!