I am creating an application in GUIDE. I've found that using the "handles" structure provided by GUIDE to store data quickly leads to messy/hard to read code. I decided that the best solution is to create my own class to handle data as well as store methods to be used in callback functions. I've been able to successfully call the constructor method in "annotatorGUI_OpeningFcn" (seen below), but when I call a class method in a different callback function, it can't find any reference to my class. Furthermore, the line "annotatorEngine = ...." is underlined in yellow with the statement "value assigned to variable might be unused". It seems that my class declaration doesn't propagate throughout the entire GUI script. I want to avoid using the "handles" structure or declaring "annotatorEngine" as global. Thanks!
EDIT: So far it seems the only thing that has worked is declaring my class object as global. However, this is still slightly annoying because in each callback, I have to write "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);
Place where I call a method.
% --------------------------------------------------------------------
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