Delete Output_Fcn in GUI

1 次查看(过去 30 天)
dadad ssasas
dadad ssasas 2022-1-23
编辑: Voss 2022-1-23
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

采纳的回答

Voss
Voss 2022-1-23
编辑:Voss 2022-1-23
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by