如何在Guide-created GUI

时间:2015-07-22 16:03:43

标签: matlab user-interface matlab-guide matlab-class

我正在GUIDE中创建一个应用程序。我发现使用"手柄" GUIDE提供的用于快速存储数据的结构导致代码混乱/难以阅读。我认为最好的解决方案是创建自己的类来处理数据以及在回调函数中使用的存储方法。我已经能够在" annotatorGUI_OpeningFcn"中成功调用构造函数方法。 (见下文),但是当我在一个不同的回调函数中调用一个类方法时,它找不到对我的类的任何引用。此外,该行" annotatorEngine = ...."用黄色下划线表示#34;赋值给变量的值可能未被使用"。似乎我的类声明并没有在整个GUI脚本中传播。我想避免使用"句柄"结构或声明" annotatorEngine"全球化。谢谢!

编辑:到目前为止,似乎唯一有用的是将我的类对象声明为全局。然而,这仍然有点烦人,因为在每次回调中,我都要编写" global annotatorEngine"。

% --- Executes just before annotatorGUI is made visible.
function annotatorGUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to annotatorGUI (see VARARGIN)

% Choose default command line output for annotatorGUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% CLASS CONSTRUCTED HERE 
annotatorEngine = annotatorGUIClass(handles.rawAxes, handles.psdAxes, handles.allPairsAxes) 

% UIWAIT makes annotatorGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);

我称之为方法的地方。

% --------------------------------------------------------------------
function loadData_Callback(hObject, eventdata, handles)
% hObject    handle to loadData (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

[FileName, PathName] = uigetfile('*.mat', 'Select a data file to load');
annotatorEngine.loadData(FileName, PathName) 


return 

0 个答案:

没有答案