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
댓글 수: 0
채택된 답변
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.)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!