Error using axes. Invalid object handle.

조회 수: 2 (최근 30일)
Tanatos Daniel
Tanatos Daniel 2014년 9월 21일
댓글: Bachtiar Muhammad Lubis 2019년 2월 6일
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
Jan
Jan 2014년 9월 21일
Please do not let us guess, which of the lines is the line 46. And post a copy of the complete error message.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2014년 9월 21일
편집: Jan 2014년 9월 21일
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
Bachtiar Muhammad Lubis
Bachtiar Muhammad Lubis 2019년 2월 6일
@Jan : How could a handles.axes doesn't contain a valid axes handle sir ? i am facing this error now

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by