GUI new callback name

3 次查看(过去 30 天)
AStro
AStro 2021-9-27
Hi,
I created Gui with a long (decriptive) name that I would like to keep but at the same time it would be good to have an option to use a shorter name just for call the gui in matlab command window. At which part of gui should I change the name so that the old remains and the new is just used for callback? I try to change it in a few place (and even in the whole gui) but each time got error message:
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)ConvertMatLab_gui('OpenSave_Callback',hObject,eventdata,guidata(hObject))
Ps. The message refers to the old name 'ConvertMatLab_gui'

回答(1 个)

Walter Roberson
Walter Roberson 2021-9-27
I can tell that you are using a GUI created with GUIDE.
Edit ConvertMatLab_gui.m
Near line 31 you will find lines
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @BrainMRI_GUI_OpeningFcn, ...
'gui_OutputFcn', @BrainMRI_GUI_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
That mfilename is pulling in the name of the .m file that is running, and storing it in the struct. Later when the helper routine gui_mainfcn() is called, that gui_Name field will be used to decide which .fig to call. But that is a problem, because the .fig still has the old name, not the new name.
You have two choices:
  1. You can edit that mfilename to be 'ConvertMatLab_gui' to hard-code the name; or
  2. Instead of changing anything in this file, have your short name be a small script that just invokes the one with the longer name. For example if the short name is CM then CM.m could contain
function varargout = cm(varargin)
if nargout == 0
ConvertMatLab_gui(varargin{:});
else
[varargout{1:nargout}] = ConvertMatLab_gui(varargin{:});
end
end
  2 个评论
AStro
AStro 2021-9-27
Thank you,
The second option works. I couldn't grasp how to proceed with option one, what exactly to edit in the hard-code :-)
Walter Roberson
Walter Roberson 2021-9-27
gui_State = struct('gui_Name', 'ConvertMatLab_gui', ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @BrainMRI_GUI_OpeningFcn, ...
'gui_OutputFcn', @BrainMRI_GUI_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
but I think the wrapper function is a better option.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by