Run a long program and a stopwatch simulaneously in a GUI?

3 views (last 30 days)
I have a program that takes a long time to run (mostly because of a griddata function). My vision was to include a GUI running in parallel with this program that updated a stopwatch at one second intervals concurrently with the long program. I used a timer object for the stopwatch, but when I run the long program, the timer objects stops to wait for the program to finish. In fact, any program appears to disrupt the timer. I've tried making the long program part of the GUI, running it on its own, even putting a timer in the long program itself. I've done some research and I think the problem has to do with the fact that MATLAB cannot run multiple programs at the same time. Is there any way around this or will I have to make due with tic tocs during program milestones? Here is my simple code for the stopwatch that I created with GUIDE. I've only included the opening function and the stopwatch function here:
function Step1DiagGUI_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
global sec min hr t
sec = '00';
min = '00';
hr = '00';
t = timer;
set(t,'ExecutionMode','fixedRate','TimerFcn',@(varargin)stopwatch(handles,varargin))
start(t)
function [] = stopwatch(handles,varargin)
global sec min hr
sec = str2double(sec);
min = str2double(min);
hr = str2double(hr);
sec = sec+1;
if sec==60
min = min+1;
sec = 0;
if min==60
hr = hr+1;
min = 0;
if hr==24
hr = 0;
end
end
end
sec = num2str(sec);
if length(sec)==1
sec = ['0' sec];
end
min = num2str(min);
if length(min)==1
min = ['0' min];
end
hr = num2str(hr);
if length(hr)==1
hr = ['0' hr];
end
set(handles.text_Time,'String',[hr ':' min ':' sec])
Where the GUI is just a simple static text box with the tag "text_Time" and initialy a string: '00:00:00'
Thank you!
  • Using R2011b if it helps
  2 Comments
Walter Roberson
Walter Roberson on 24 Oct 2012
Have you considered "accepting" Answers to your previous Questions to encourage volunteers to spend more time on your Question ?
Andrew
Andrew on 24 Oct 2012
Sorry about that, still kind of new to this. Done.

Sign in to comment.

Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!