Azzera filtri
Azzera filtri

When an error occurs how I can restar the mfile from a specific line?

1 visualizzazione (ultimi 30 giorni)
Hi there,
I'm using the Optimization Toolbox with the Genetic Algorithm (GA) in order to optimize the discretization of a continuous variable. When the funcion runs happens that if the discretization, generated by the GA, is bad the software get an error and stops. I want to find a way to jump the error and allow the GA to execute until to finding the optimum discretization, so:
if generic error
restart from line xx
Thanks

Risposte (2)

Matt J
Matt J il 19 Gen 2013
Use TRY and CATCH at the line where the error occurs.

Image Analyst
Image Analyst il 19 Gen 2013
As far as I know, there is no way, short of putting every single line of code inside the "try" block of a try/catch construct, which is obviously not practical except for the shortest script where you can just step though with the debugger anyway.
There is no "resume next" as there is in Visual Basic. In Visual Basic you can put "resume next" in the catch block and it will return and pick up at the line right after where the exception occurred. Unfortunately no such capability in MATLAB though on a few occasions I have wished for it. You just have to rearrange your code to (as much as possible) put as much of the code that is crucial to get executed near the top of the routine, and error prone code (like checking if some kind of hardware or device is attached to your computer) near the end of the routine.

Community Treasure Hunt

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

Start Hunting!

Translated by