下面是一个M文件的例题,我想用GUI界面来做,结果出错了,麻烦大家帮我看以下!
function varargout = exercise01(varargin)
% EXERCISE01 M-file for exercise01.fig
% EXERCISE01, by itself, creates a new EXERCISE01 or raises the existing
% singleton*.
%
% H = EXERCISE01 returns the handle to a new EXERCISE01 or the handle to
% the existing singleton*.
%
% EXERCISE01('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in EXERCISE01.M with the given input arguments.
%
% EXERCISE01('Property','Value',...) creates a new EXERCISE01 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before exercise01_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to exercise01_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
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help exercise01
% Last Modified by GUIDE v2.5 16-Apr-2009 16:47:20
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @exercise01_OpeningFcn, ...
'gui_OutputFcn', @exercise01_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 exercise01 is made visible.
function exercise01_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 exercise01 (see VARARGIN)
% Choose default command line output for exercise01
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes exercise01 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
t=0:pi/24:4*pi;
y=sin(t);
plot(t,y,'b')
n=length(t);
h=line('color',[0 0.5 0.5],...
'linestyle','.',...
'markersize',25,...
'erasemode','xor');
% --- Outputs from this function are returned to the command line.
function varargout = exercise01_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)
i=1;
k=1;
m=0;
while 1
if k==0
break
end
if k~=0
set(handles.h_axes,'xdata',t(i),'ydata',y(i))
drawnow;
i=i+1;
if i>n
m=m+1;
i=1;
end
end
end
% 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)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
close
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (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,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (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,'String') returns contents of edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
出错的提示是:
??? Reference to non-existent field 'h_axes'.
Error in ==> exercise01>pushbutton1_Callback at 95
set(handles.h_axes,'xdata',t(i),'ydata',y(i))
Error in ==> gui_mainfcn at 75
feval(varargin{:});
Error in ==> exercise01 at 44
gui_mainfcn(gui_State, varargin{:});
??? Error while evaluating uicontrol Callback.
[本帖最后由 mooni 于 2009-4-17 09:51 编辑]