GUI new callback name

1 view (last 30 days)
AStro
AStro on 27 Sep 2021
Commented: Walter Roberson on 27 Sep 2021
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'

Answers (1)

Walter Roberson
Walter Roberson on 27 Sep 2021
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 Comments
Walter Roberson
Walter Roberson on 27 Sep 2021
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!