求教如何在GUI中的AXES中利用定时器制作动画?
下面的代码只能显示初值点 无法实现动画 不知道为什么?
另外AXES的坐标轴怎么样才能固定住?
代码如下
function varargout = drawtest(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @drawtest_OpeningFcn, ...
'gui_OutputFcn', @drawtest_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 drawtest is made visible.
function drawtest_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 drawtest (see VARARGIN)
% Choose default command line output for drawtest
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes drawtest wait for user response (see UIRESUME)
% uiwait(handles.figure1);
NowTime1=clock;
global begintime
begintime=NowTime1(4)+NowTime1(5)+NowTime1(6);
global x
x=100;
global y
y=100;
handles.timer = timer('Period',0.05,'ExecutionMode','FixedRate','TimerFcn',{@PlotUpdate,handles});
start(handles.timer);
set(gcf, 'DeleteFcn', {@DeleteFcn, handles.timer});
function PlotUpdate(obj,events,handles)
global begintime
global x
global y
NowTime=clock;
plottime=NowTime(4)+NowTime(5)+NowTime(6)-begintime;
handles.h=plot(x,y,'.');
set(handles.h,'parent',handles.DH);
set(handles.h,'EraseMode','none','MarkerSize',21)
drawnow
x=100+100*cos(plottime);
y=100+150*sin(plottime);
set(handles.h,'XDate',x,'YDate',y);
function DeleteFcn(hObject, eventdata, t) %停止计时器
stop(t);
delete(t); %销毁定时器
clear all;
% --- Outputs from this function are returned to the command line.
function varargout = drawtest_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 during object creation, after setting all properties.
function DH_CreateFcn(hObject, eventdata, handles)
% hObject handle to DH (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 DH
set(hObject,'XLim',[0 1440],'YLim',[0 900]);