Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Jay Samin
Jay Samin le 25 Août 2016
Commenté : Jay Samin le 26 Août 2016
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

Réponse acceptée

Geoff Hayes
Geoff Hayes le 25 Août 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 commentaire
Jay Samin
Jay Samin le 26 Août 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by