- You can edit that mfilename to be 'ConvertMatLab_gui' to hard-code the name; or
- 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
GUI new callback name
10 次查看(过去 30 天)
显示 更早的评论
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'
0 个评论
回答(1 个)
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:
function varargout = cm(varargin)
if nargout == 0
ConvertMatLab_gui(varargin{:});
else
[varargout{1:nargout}] = ConvertMatLab_gui(varargin{:});
end
end
2 个评论
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 Center 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!