Disabling a Button after pressed - GUI

Im getting this error message for a GUI
Struct contents reference from a non-struct array object.
I have the student use version.
Error in JOSHSPOKER>pushbutton1_Callback (line 84)
set(handles.pushbutton1,'enable','off')
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in JOSHSPOKER (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)JOSHSPOKER('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
This is my code:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%DISABLE!!!
set(handles.pushbutton1,'enable','off')
set(handles.pushbutton1,'visible','off')
[MyCard1, MyCard2, TheirCard1, TheirCard2] = shuffle

Answers (1)

Somehow, your handles structure is not a handles structure. Either:
  1. it was never set up properly (e.g., you did not use GUIDE and you did not create it yourself); or
  2. you have used it before it is set up properly (but it should already have been done by the time any callback can be invoked); or
  3. it has been corrupted, such as you somewhere call
guidata(hObject,handles)
after handles had been set to a non-structure.

8 Comments

Thank you for your input. It was my own guide. I opened the guide and made the pushbutton. Rightclicked and callbacks. Saved. Then went to the function. Ive tried several times over and over. Is this normal to display on the function that was called? There was a red underline. It is my own code created in guide. I never adjusted handles anywhere before.
Explanation It appears that the code never uses the indicated local function or nested function because: There is no obvious call of the function. The code does not compute a function handle for the function. The code does not include a string containing the name of the function. If the code had such a string, Code Analyzer would not produce this message because it would indicate that the string might be passed to feval or a callback. Code Analyzer can present this message erroneously for several reasons, including:
Is there any more code that could help solve this? BTW im using Matlab R2015b student use.
We need to see your complete .m file that was written by GUIDE.
function varargout = JOSHSPOKER(varargin)
% JOSHSPOKER MATLAB code for JOSHSPOKER.fig
% JOSHSPOKER, by itself, creates a new JOSHSPOKER or raises the existing
% singleton*.
%
% H = JOSHSPOKER returns the handle to a new JOSHSPOKER or the handle to
% the existing singleton*.
%
% JOSHSPOKER('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in JOSHSPOKER.M with the given input arguments.
%
% JOSHSPOKER('Property','Value',...) creates a new JOSHSPOKER or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before JOSHSPOKER_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to JOSHSPOKER_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 JOSHSPOKER
% Last Modified by GUIDE v2.5 19-Mar-2016 21:51:17
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @JOSHSPOKER_OpeningFcn, ...
'gui_OutputFcn', @JOSHSPOKER_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 JOSHSPOKER is made visible.
function JOSHSPOKER_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 JOSHSPOKER (see VARARGIN)
clc
% Choose default command line output for JOSHSPOKER
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes JOSHSPOKER wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = JOSHSPOKER_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 button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%DISABLE!!!
[MyCard1, MyCard2, TheirCard1, TheirCard2] = shuffle
set(handles.pushbutton1, 'Enable', 'off')
set(handles.pushbutton1, 'Visible', 'off')
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
[y] = cardimage(handles.c1);
% Hint: place code in OpeningFcn to populate axes1
% --- Executes during object creation, after setting all properties.
function axes2_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes2
I guess I will need the .fig as well.
I will send the fig as soon as i can. Thanks for your help.
I think I have to designate pushbutton1 as hObject???
These were saved at the same time.

Sign in to comment.

Categories

Find more on Graphics Object Properties 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!