How do I add a timer to a button push function that creates a scatter plot?
이전 댓글 표시
I have a button push function right now that creates a scatter plot with randomly spaced dots and exes. I need to make a timer that starts when the button which plots the scatter plot is pushed and stops when another key such as 1 or 2 is pressed and records the time elapsed and I am not sure how to do this. Does anyone now how? Thanks in advance for your help!
function buttonPlot
% Create a figure window
fig = uifigure;
% Create a UI axes
ax = uiaxes('Parent',fig,...
'Xlim',[0 10], 'YLim',[0 10],...
'Position',[104, 123, 300, 201]);
%create tic toc timer? Not sure how do do this part
% Creat button push
btn = uibutton(fig,'push',...
'Position',[420, 218, 100, 22],...
'ButtonPushedFcn', @(btn,event) plotButtonPushed(btn,ax));
end
% Create the function for the ButtonPushedFcn callback
function plotButtonPushed(btn,ax)
x1 = rand(1,10)*10;
y1 = rand(1,10)*10;
x2 = rand(1,10)*10;
y2 = rand(1,10)*10;
scatter(ax,x1,y1,100,"green","filled","o")
hold(ax,'on')
scatter(ax,x2,y2,150,"red","+")
hold(ax,"off")
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!