GUIDE gui output -- "Attempt to reference field of non-structure array"

1 view (last 30 days)
Hello!
I have a simple GUIDE gui that uses a slider to change the value in a static text box, as part of a larger project. I can get the value to change properly (have modified the slider step to do that). However, I need to have the gui output the value that was selected when the gui closes for use in other guis.
I keep getting "Attempt to reference field of non-structure array" when I run this. The code follows, and there are a number of %commented out attempts I have made. I've searched the Answers and looked at Doug Hull's video, and can't figure out what's wrong. Help is appreciated!
Doug Anderson
function varargout = slider_test3(varargin)
% SLIDER_TEST3 MATLAB code for slider_test3.fig
% SLIDER_TEST3, by itself, creates a new SLIDER_TEST3 or raises the existing
% singleton*.
%
% H = SLIDER_TEST3 returns the handle to a new SLIDER_TEST3 or the handle to
% the existing singleton*.
%
% SLIDER_TEST3('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SLIDER_TEST3.M with the given input arguments.
%
% SLIDER_TEST3('Property','Value',...) creates a new SLIDER_TEST3 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before slider_test3_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to slider_test3_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help slider_test3
% Last Modified by GUIDE v2.5 12-Feb-2014 08:48:46
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @slider_test3_OpeningFcn, ...
'gui_OutputFcn', @slider_test3_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 slider_test3 is made visible.
function slider_test3_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 slider_test3 (see VARARGIN)
% Choose default command line output for slider_test3
set(handles.slider1,'Value',2);
set(handles.slider1,'Max',22);
set(handles.slider1,'Min',2);
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes slider_test3 wait for user response (see UIRESUME)
uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = slider_test3_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
% set(handles.output,'String','Junko'); %num2str(get(handles.slider1))); % = handles.slider1; %get(handles.slider1,'Value');
varargout{1} = handles.text3; %output; %'Junk'; %get(handles.slider1,'Value') ; %output;
%guidata(hObject,handles);
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.text3,'String',(get(hObject,'Value')));
%set(handles.text3,'String',(get(handles.slider1,'Value')));
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: delete(hObject) closes the figure
%handles.output = handles.text3;
delete(hObject);
if true
% code
end
  2 Comments
Douglas Anderson
Douglas Anderson on 12 Feb 2014
Hello again,
I wanted to add a comment: I just tried following Doug Hull's video on "Advanced getting an output from a guide gui" step by step from a blank gui, and got the same message "Attempt to reference field of non-structure array" when I tried to run "a = main", which should just give the handle!
Walter Roberson
Walter Roberson on 12 Feb 2014
Which line is the problem occurring on?
When you run the code be sure to run
slider_test3
and not
slider_test3.m
Also, you cannot run it by double-clicking on the .fig file; that will not work.

Sign in to comment.

Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!