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

1 次查看(过去 30 天)
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

采纳的回答

Geoff Hayes
Geoff Hayes 2016-8-25
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 个评论
Jay Samin
Jay Samin 2016-8-26
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by