Error using axes. Invalid object handle.
4 views (last 30 days)
Show older comments
I created a matlab GUI with togglebutton1 and axes1. I would like to push the button and view the -signal plotted in axes1. Here is my code. I tried to make it as small as I could in order to expose the problem.
function varargout = untitled3(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled3_OpeningFcn, ...
'gui_OutputFcn', @untitled3_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
function untitled3_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
global buttonState
buttonState=1;
global Fs
global T
global recObj
global i
global sig
global r
Fs = 8000; %# sampling frequency in Hz
T = 0.03; %# length of one interval signal in sec
%# prepare audio recording
recObj = audiorecorder(Fs,8,1);
i=1;
while (buttonState)
recordblocking(recObj, T);
sig = getaudiodata(recObj);
r=xcorr(sig,'coeff');
axes(handles.axes1);
subplot(3,1,3);
plot(r);
legend('Autocorrelation');
xlabel('Delay (s)');
ylabel('Correlation coeff.');
drawnow %# force MATLAB to flush any queued displays
i=i+1;
end
function varargout = untitled3_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function togglebutton1_Callback(hObject, eventdata, handles)
isPushed=get(hObject,'Value');
if isPushed
i=1;
buttonState=0;
set (hObject, 'String', 'Stop');
else
buttonState=1;
set (hObject, 'String', 'Start');
end
It almost does that, but when I press exit, I get the error on line 46.
1 Comment
Jan
on 21 Sep 2014
Please do not let us guess, which of the lines is the line 46. And post a copy of the complete error message.
Answers (1)
Jan
on 21 Sep 2014
Edited: Jan
on 21 Sep 2014
Using the debugger is the standard for solving such problems. Type in the command window:
dbstop if error
Then run the code again until the error appears. Now you can inspect the locally used variables, I guess the handles struct is the problem and handles.axes1 does not contain a valid axes -handle.
1 Comment
Bachtiar Muhammad Lubis
on 6 Feb 2019
@Jan : How could a handles.axes doesn't contain a valid axes handle sir ? i am facing this error now
See Also
Categories
Find more on Graphics Objects in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!