GUI new callback name

조회 수: 5 (최근 30일)
AStro
AStro 2021년 9월 27일
댓글: Walter Roberson 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에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by