Using a timer to iterate through a for loop
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am trying to use a timer to advance to the next iteration of a for loop, if a function called within the for loop takes more than 5 seconds to complete:
for n = 1 : tot
t = timer('TimerFcn', 'continue', 'StartDelay', 5);
start(t)
[pmsk{n}, crv{n}, mline{n}, smsk{n}, tcrd{n}, dsts{n}] = runStraighteningPipeline(img.readimage(n)); %% This is the process I am trying to end if it keeps running for more than 5 seconds
fname{n} = getDirName(img.Files{n});
msg = sprintf('Successfully processed: %s', fname{n}); disp(msg);
stop(t)
delete(t)
end
However, I receive the following error when the timer elapses:
Error while evaluating TimerFcn for timer 'timer-10'
Error: A CONTINUE may only be used within a FOR or WHILE loop.
I assume this is because MATLAB is running code within "runStraighteningPipeline", and isn't explicitly within the for loop when the timer is triggered. Is there any way around this?
I don't want to break out of the loop, I just want to advance to the next value of "n", if this subprocess takes too long.
Thanks!
3 Commenti
dpb
il 20 Giu 2019
I think you'll have to get more subtle than that...the timer will need a function body, and, I'm guessing, to rethrow the error as caller. Will need to probe the MException stack to determine just how that is organized and, if there are other functions inside the runStraighteningPipeline function as almost certainly will be, you may have to walk your way back up the stack from several levels of nesting dependent upon where execution is at the time the timer fires.
This may not be fun and may, (or may not) even be doable, I don't know for certain...this might be one to pose over on the Matlab Undocumented site for Yair--it's the kind of thing he's probably poked around at at some time or the other...
Risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!