MATLAB Answers

0

delete splash screen from background

Asked by Tyler Murray on 30 Nov 2016
Latest activity Answered by Geoff Hayes
on 4 Dec 2016
I am adding a splash screen while my standalone matlab gui loads using the functions
function gui_OpeningFcn(hObject, ~, 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 guiTest (see VARARGIN)
% Choose default command line output for guiTest
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
if strcmp(get(hObject,'Visible'),'off')
initialize_gui(hObject, handles);
end
function initialize_gui(hObject, fig_handle, handles)
splash = imshow(imread('splash.png'),[0,255]);
I am trying to delete the variable splash once the gui loads. I have looked on the mathworks file share site but feel this way is much easier. I just can't figure out how to delete splash once the gui is loaded. I imagine I can create an if statement saying if (edittextbox, 'Visible', 'On') delete(splash) but that hasn't worked yet. Would I place that if statement under the initialize_gui function or underneath the callback function of the editText?

  0 Comments

Sign in to comment.

1 Answer

Answer by Geoff Hayes
on 4 Dec 2016

Tyler - I don't think that adding a splash screen/image to the OpeningFcn of your GUI is the right way to go. From https://www.mathworks.com/help/matlab/creating_guis/initializing-a-guide-gui.html, the opening function is the first callback in every GUIDE code file. It is executed just before the UI is made visible to the user, but after all the components have been created, i.e., after the components' CreateFcn callbacks, if any, have been run. So it seems a little too late at this point to launch the splash image because the GUI is just about ready to be made visible.
You may want to consider creating a separate GUI which just acts as a splash screen. It would show your image (as the splash) and then start a timer (all from within its OpeningFcn). When the timer expires, the second GUI would be launched and when its OpeningFcn is called and is about to finish, it could then find the handle to the first GUI (the splash screen) and close it. Note that you would need to set the HandleVisibility property to On for the first GUI so that you can find it from your second. See https://www.mathworks.com/matlabcentral/answers/146215-pass-data-between-gui-s for an example.

  0 Comments

Sign in to comment.