function PlotUpdateExample
x = 0:0.1:10;
m = 1;
hFig = figure('Position',[360,500,450,285]);
hStartBtn = uicontrol('Style','pushbutton',...
'CallBack', @StartButtonCallback, ...
'String','Start','Position',[315,220,70,25]);
hUpdateBtn = uicontrol('Style','pushbutton',...
'CallBack', @UpdateButtonCallback, ...
'String','Update','Position',[315,180,70,25]);
hAxes = axes('Units','pixels','Position',[50,60,200,185]);
hLine = plot(NaN, NaN, 'color','r','Marker','o');
axis(hAxes, 'equal');
set(hAxes, 'XLim', [min(x) max(x)]);
myTimer = timer('Name','MyTimer', ...
'Period',0.5, ...
'StartDelay',1, ...
'TasksToExecute',inf, ...
'ExecutionMode','fixedSpacing', ...
'TimerFcn', @timerCallback);
function StartButtonCallback(hObject, eventdata)
start(myTimer);
end
function UpdateButtonCallback(hObject, eventdata)
m = m + 0.5;
end
function timerCallback(hObject, eventdata)
if index > length(x)
stop(myTimer);
else
set(hLine, 'XData', [get(hLine, 'XData') x(index)], 'YData', [get(hLine, 'YData') m * x(index)]);
index = index + 1;
drawnow;
end
end
end
0 Comments
Sign in to comment.