Hi,
I have a "handles.anglenames" that I write into my guide GUI's opening function.
When I run the code however, I get the following error:
"Attempt to reference field of non-structure array.Error in ZenKinematicsTest>graphpop1_CreateFcn (line 133)set(hObject,'String',handles.anglenames);"
and upon debugging, I realise that at some point in my code, handles suddenly becomes empty. Inside the opening function it is as it should be (i.e. contains the handles to all my gui objects, and also has handles.anglenames) … but once it enters any of the createFcns, suddenly handles = []
The code is below, and I've attached the m file and fig as well. No idea what's going on I'm afraid..! 🙁 I'm using Matlab 2014b.
function varargout = ZenKinematics(varargin)% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @ZenKinematics_OpeningFcn, ... 'gui_OutputFcn', @ZenKinematics_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []);if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1});endif 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 ZenKinematics is made visible.
function ZenKinematics_OpeningFcn(hObject, eventdata, handles, varargin)handles = guidata(hObject);handles.anglenames = {'Knee','Ankle','Hip'};uiwait(hObject);guidata(hObject,handles);% --- Outputs from this function are returned to the command line.
function varargout = ZenKinematics_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)% hObject handle to popupmenu1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');end%handles = guidata(hObject);
%handles.ref = getappdata(0,'handlesL');
%set(handles.popupmenu1, 'String', handles.ref.dancernames);
%guidata(hObject, handles)
% --- Executes on selection change in graphpop1.
function graphpop1_Callback(hObject, eventdata, handles)% hObject handle to graphpop1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: contents = cellstr(get(hObject,'String')) returns graphpop1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from graphpop1
handles = guidata(hObject);AngleID = find(strcmp(handles.anglenames,contents));disp(AngleID)% --- Executes during object creation, after setting all properties.function graphpop1_CreateFcn(hObject, eventdata, handles)% hObject handle to graphpop1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: popupmenu controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endset(hObject,'String',handles.anglenames);% --- Executes during object creation, after setting all properties.function graph1_CreateFcn(hObject, eventdata, handles)% hObject handle to graph1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called
Best Answer