how to run a loop parallel

Hi,
is there a way to run a loop parallel (like a timer would do) to the rest of the programm? I want to start it by a start command and end it by a stop command. (quasi a timer with Period = 0)

Answers (1)

Jan
Jan on 26 Sep 2013

0 votes

No, there is no such method. What about using a timer?

6 Comments

yes plan b. should work also.
Jan
Jan on 26 Sep 2013
The call it plan A. :-)
Adrian
Adrian on 26 Sep 2013
Edited: Adrian on 26 Sep 2013
Then I have another question: I already have a timer which has a "long" callback fcn. During this execution I want the second timer to be executed periodically (best with a delay of 0s). Therefor I created a second timer obj and started it at the beginning of the first timers callback. It doesn't work :(
Is it not possible to start a timer out of a timers callback?
Jan
Jan on 26 Sep 2013
"It doesn't work" is not detailed enough to suggest an improvement. Please post a piece of code with reproduces the observed behavior and explain what happens. If you get an error message, post a complete copy.
Ok, I created a GUI with GUIDE. Added a Static text field (text1) and a CloseRequestFcn.
Then I added following Code to the generated:
Added to the OpeningFcn:
handles.tim2 = timer('TimerFcn', {@timer2_callback_fcn, handles}, 'Period', 0.001, 'ExecutionMode', 'FixedSpacing');
guidata(hObject, handles);
handles.tim = timer('TimerFcn', {@timer_callback_fcn, handles}, 'ExecutionMode', 'fixedSpacing', 'StartDelay', 1, 'Period', 2);
start(handles.tim);
After that I added the two timer CallbackFcn:
First one:
function timer_callback_fcn(obj, event, handles)
start(handles.tim2);
pause(10);
stop(handles.tim2);
set(handles.text1, 'str', 'stop');
Second one:
function timer2_callback_fcn(obj, event, handles)
set(handles.text1, 'str', 'running');
The CloseRequestFcn I expanded by:
stop(handles.tim2);
stop(handles.tim);
delete(handles.tim2);
delete(handles.tim);
If I run the GUI 'stop' is displayed after 10 seconds . 'running' doesn't appear. Errors aren't displayed.
Added files: - 'testgui.zip' containing 'testgui.fig' and 'testgui.m'

Sign in to comment.

Categories

Products

Asked:

on 26 Sep 2013

Commented:

on 27 Sep 2013

Community Treasure Hunt

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

Start Hunting!