Borrar filtros
Borrar filtros

how to Automate a button click after X-Seconds to update values

2 visualizaciones (últimos 30 días)
Hi everyone,
I have an issue with MATLAB GUIs that I don't know how to solve. i want to automate the "Push Button" so that after x-Seconds the values off my Variables(Distance traveled, Required_Energy ...) be updated automatically. (The variables are available as Vector in workspace)
basically I want to run the Butto after x-Second automatically without have to click on it.
I was thinking about a Solution with timer but i dont know how to do it.
i will apreciate any Help many thanks Jay

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 25 de Ag. de 2016
Jay - are these variables in your workspace because you are using Simulink? If so, you could create a timer object in the OpeningFcn of your GUI as
handles.timer = timer('Name','MyTimer', ...
'Period',5, ...
'StartDelay',1, ...
'TasksToExecute',inf, ...
'ExecutionMode','fixedSpacing', ...
'TimerFcn',{@timerCallback,handles.figure1});
guidata(hObject,handles);
start(handles.timer);
In the above, we create the timer that will fire every five seconds. We assign a callback, timerCallback, and pass an additional parameter which the handle to the GUI/figure. We then save the updated handles structure and start the timer.
Your callback would then be
function [] = timerCallback(~,~,guiHandle)
if ~isempty(guiHandle)
% get the handles
handles = guihandles(guiHandle);
% collect your data from the workspace
% update the text fields of your GUI using *handles*
% an example:
% find the distance traveled
distTraveled = randi(255,1,1);
% update the distance traveled text field
set(handles.textDistanceTraveled,'String',num2str(distTraveled));
end
You would probably need to use evalin to get your data from the base workspace. textDistanceTraveled is the name/tag for your distance traveled text field. (I suspect that it is quite different in your code.)
Try the above and see what happens! (See also https://www.mathworks.com/matlabcentral/answers/178682-collecting-a-variable-every-two-minutes for a similar problem.)
  1 comentario
Jay Samin
Jay Samin el 26 de Ag. de 2016
Hi Geoff,
thank u for the Quick answer :) yes, im getting the variables from Simulink. i will try it and let u know.
thnx again

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by