Hi folks,
Building my first GUI programmatically and hitting a snag early on.
Can anyone tell me why I am getting the error
Reference to non-existent field 'popbutt2'.Error in maingui/updateAxes (line 83)yColNum = get(hs.popbutt2, 'value');Error in maingui/popbutt1 (line 93)updateAxes(hObject, eventdata, hs)Error while evaluating UIControl Callback
In the code below:
function mainguihs = addcomponents;hs.Fig.Visible = 'on';%%Create tabbed GUI
function hs = addcomponents hs.hFig = figure('Name', 'Main', ... 'Position', ... [20 100 1870 850]); s = warning('off', 'MATLAB:uitabgroup:OldVersion');%%Build Tabs
hs.TabGroup = uitabgroup('Parent',hs.hFig, 'Position', [ .01 .01 .98 .975 ]); warning(s); hs.Tabs(1) = uitab('Parent',hs.TabGroup, 'Title',' Preprocessing '); hs.Tabs(2) = uitab('Parent',hs.TabGroup, 'Title',' Data '); hs.Tabs(3) = uitab('Parent',hs.TabGroup, 'Title',' Report '); set(hs.TabGroup, 'SelectedTab',hs.Tabs(1)); hs.TextBox = uicontrol('style','text', 'Position', [ 800 820 250 30] ); set(hs.TextBox,'String',' Main Processing Interface', ... 'Units', 'Characters', 'FontSize', 14, 'ForegroundColor', [ 0 0 0]); %%Create Tab 1 Panels
%# populate tabs with UI components
hs.DataPanel1 = uipanel('Parent', hs.Tabs(1), 'Position', [.01 .01 .98 .98], 'BackgroundColor', 'white'); hs.DataPanel2 = uipanel('Parent', hs.DataPanel1, 'Position', [ .01 .9 .4 .08]); %DataPanel3 = uipanel('Parent', DataPanel2, 'Position', [ .3 .3 .55 .6], 'BackgroundColor', 'white');
hs.textload = uicontrol('Style','text', 'String','No File Currently Loaded', ... 'Parent',hs.DataPanel2, 'Position', [ 130 15 450 30], 'FontSize', 12); set(hs.textload,'callback', {@loadbutt1, hs}); % Plot 1
hs.ax1 = axes('Parent', hs.DataPanel1, 'units', 'normalized', 'Position', [.1 .5 .3 .3], 'box', 'on'); % X Axis Popup for Plot 1
hs.popbutt1 = uicontrol('Style','popupmenu', 'String','*', ... 'Parent',hs.Tabs(1), 'Position', [40 500 100 100]); set(hs.popbutt1,'callback',{@popbutt1,hs}); % Y Axis Popup for Plot 1
hs.popbutt2 = uicontrol('Style','popupmenu', 'String','*', ... 'Parent',hs.Tabs(1), 'Position', [40 400 100 100]); set(hs.popbutt2,'callback',{@popbutt2,hs}); % Load Data Button
hs.loadbutt1 = uicontrol('Style','pushbutton', 'String','Load Data', ... 'Parent',hs.DataPanel2, 'Position', [ 10 18 100 30]); set(hs.loadbutt1,'callback',{@loadbutt1,hs}); % Filename
end % Executes on button press in loadbutt1
function hs = loadbutt1(hObject, eventdata, hs) hs.fileName = uigetfile('*.*'); guidata(hObject, hs); set(hs.textload,'string',hs.fileName); setpopmenuString(hs.popbutt1, eventdata, hs); setpopmenuString(hs.popbutt2, eventdata, hs); guidata(hObject, hs); [numbers, colNames] = xlsread(hs.fileName); hs.numbers = numbers updateAxes(hObject, eventdata, hs); guidata(hObject, hs); end% Set Figure 1 Axis as per XLS Row 34
function hs = setpopmenuString(hObject, eventdata, hs)guidata(hObject, hs);fileName = hs.fileName;[numbers, colNames] = xlsread(hs.fileName);hs.numbers = numberscolNames2 = colNames(34,:)';set(hObject,'string', colNames2);guidata(hObject, hs);end% XLSRead to Populate Popupmenu Columns
function [x,y]= readExcelColumns(fileName, xColNum, yColNum)a = xlsread(fileName);x = a(:,xColNum);y = a(:,yColNum);end% Plotting Function for Ax1
function hs = updateAxes(hObject, eventdata, hs)guidata(hObject, hs);xColNum = get(hs.popbutt1, 'value');yColNum = get(hs.popbutt2, 'value');x = hs.numbers(:,xColNum);y = hs.numbers(:,yColNum);fileName = hs.fileName;[x,y]= readExcelColumns(fileName, xColNum, yColNum);plot(hs.ax1, x,y) endfunction hs = popbutt1(hObject, eventdata, hs)updateAxes(hObject, eventdata, hs)end function hs = popbutt2(hObject, eventdata, hs) updateAxes(hObject, eventdata, hs) end end
Apologies if I am missing some protocol here, would appreciate any clues or tips at all.
I have used the Debugger and when I pause on
function hs = updateAxes(hObject, eventdata, hs)guidata(hObject, hs);xColNum = get(hs.popbutt1, 'value');
the last line, I can see the 'hs' structure doesn't include popbutt2, I'm just not sure why…
Matt
Best Answer