Error using axes. Invalid object handle.

6 ビュー (過去 30 日間)
Tanatos Daniel
Tanatos Daniel 2014 年 9 月 21 日
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 Center および File ExchangeGraphics Object Properties についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by