Delete Output_Fcn in GUI

2 views (last 30 days)
dadad ssasas
dadad ssasas on 23 Jan 2022
Edited: _ on 23 Jan 2022
Hello,
i made a GUI in which exist several buttons etc. It doesnt need an input from command window.
So the usage of openingFcn, which is created automaticaly is clear for me. But why do i need the function which is executed after openingFcn.
The "function varargout = nameofFile_outputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
I already visited some threads but i couldnt exactly understand why i need it for. As far as i understand it can be used with the uiwait command so the user can do something and then the output fcn executes. My question can i just delete it somehow ?
Thanks

Accepted Answer

_
_ on 23 Jan 2022
Edited: _ on 23 Jan 2022
The outputFcn is for returning a handle to your figure (and additional outputs if you like), so you can call your m-file like this:
hFig = nameOfFile();
and then do stuff to the figure (now stored in the variable hFig) programmatically (including uiwait() for it, yes).
You may never need to do that, so yes, you can delete the outputFcn. But if you do, then you will need to edit the part at the top of your m-file that says, "DO NOT EDIT".
The line that looks like this:
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @nameOfFile_OpeningFcn, ...
'gui_OutputFcn', @nameOfFile_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
can be changed to this:
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @nameOfFile_OpeningFcn, ...
'gui_OutputFcn', @do_nothing, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
where do_nothing() is a function that looks like this:
function do_nothing(varargin)
end
Then you can't call your m-file with an output argument, as in the previous syntax:
hFig = nameOfFile();
or you will get an error.
All in all, it's probably easier to just leave it alone and not worry about it.
Note that doing the above deletes the function nameOfFile_OutputFcn, but the GUI itself still has an outputFcn, which is now do_nothing. The GUI needs some outputFcn, even if it doesn't do anything and is never used, because gui_mainfcn looks for it, and you do not want to be editing that.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by