How do I add a timer to a button push function that creates a scatter plot?
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Annotations dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!