我仍在学习如何使用 MATLAB 的 gui。我使用了 GUIDE 的模板之一,正是GUI with Axes and Menu
.
这会生成两个文件:GUIFigure.m 和 GUIFigure.fig
起初,我删除了为弹出菜单提供标签的行,如下所示:
function popupmenu1_CreateFcn(hObject, eventdata, handles)
set(hObject, 'String', {'old text 1', 'old text 2');
当我用自己的文本替换大括号内的文本时,效果很好。当我用单元格变量替换它并使用不正确的语法时,它会给我一个错误,这是可以理解的,但该图仍然会弹出旧文本。
另一个类似的问题是该示例已经有一个带有轴的图。现在我从 .fig 文件中删除了坐标轴,并且我还在 .m 文件中删除了它们的代码。但是,当我运行 gui 函数时,坐标轴仍然显示在绘图中,尽管我什至删除了为绘图生成数据的代码!
任何关于正在发生的事情的解释/提示将不胜感激。
function varargout = FIAFigure(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @FIAFigure_OpeningFcn, ...
'gui_OutputFcn', @FIAFigure_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before FIAFigure is made visible.
function FIAFigure_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for FIAFigure
handles.output = hObject;
handles.dataSetsCell = varargin{1};
handles.categoryNames = varargin{2};
% Update handles structure
guidata(hObject, handles);
if strcmp(get(hObject,'Visible'),'off')
plot(rand(5));
end
% --- Outputs from this function are returned to the command line.
function varargout = FIAFigure_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
t = uitable(handles.uitable1);
cla;
popup_sel_index = get(handles.popupmenu1, 'Value');
set(t,'Data',magic(popup_sel_index))
% --------------------------------------------------------------------
function FileMenu_Callback(hObject, eventdata, handles)
% --------------------------------------------------------------------
function OpenMenuItem_Callback(hObject, eventdata, handles)
file = uigetfile('*.fig');
if ~isequal(file, 0)
open(file);
end
% --------------------------------------------------------------------
function PrintMenuItem_Callback(hObject, eventdata, handles)
printdlg(handles.figure1)
% --------------------------------------------------------------------
function CloseMenuItem_Callback(hObject, eventdata, handles)
selection = questdlg(['Close ' get(handles.figure1,'Name') '?'],...
['Close ' get(handles.figure1,'Name') '...'],...
'Yes','No','Yes');
if strcmp(selection,'No')
return;
end
delete(handles.figure1)
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
set(hObject, 'String', {handles.categoryNames{1:end}});
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes during object creation, after setting all properties.
function uitable1_CreateFcn(hObject, eventdata, handles)