Borrar filtros
Borrar filtros

How to display the current result when the program is forced to abort?

2 visualizaciones (últimos 30 días)
How to display the current result when the program is forced to abort? When I use "ctrl+c" to abort the running of program, it doesnot show any result.
  2 comentarios
Chandler Hall
Chandler Hall el 13 de Nov. de 2022
Are you trying to inspect the data for the purpose of debugging? Consider setting a conditional breakpoint which will allow you to pause execution when a loop variable reaches a particular value, for example.
Qiandong Dong
Qiandong Dong el 14 de Nov. de 2022
I'm calculating a large-scale problem. Because the computation takes so long, I just want to compute the solution at a specific time.

Iniciar sesión para comentar.

Respuestas (2)

Star Strider
Star Strider el 13 de Nov. de 2022
One option would be to save the intermediate results to a .mat file. It might be necessary to re-write it in each iteration of a loop, or using the procedure described in Append Variable to MAT-File to save different variables in different parts of the script, however it should be available to load and examine later even if the running script is stopped.
  2 comentarios
Qiandong Dong
Qiandong Dong el 14 de Nov. de 2022
There is no iterations. I'm calculating a large-scale problem. Because the computation takes so long, I just want to compute the solution at a specific time, e.g., 1 hour.
Star Strider
Star Strider el 14 de Nov. de 2022
In that situation, I would recommend saving the intermediate results to a .mat file, and appending the appropriate variables as they are created. Then load the .mat file later to see what it contains.

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 14 de Nov. de 2022
There is no way to catch a control-c to be able to perform action such as saving current values of variables.
If you are executing within the high performance mathematical libraries, such as calculation of eigenvalues of large arrays, then control-c cannot interrupt until the library routine returns to matlab. In such cases there are no accessible intermediate variables for those routines.
You can use parfeval() to start non-graphics code in a different process or thread. In such cases you can cancel() the worker after a particular time. However, intermediate variables are not communicated back when you do that.
There is a way to examine variables in a running worker, but I am having trouble finding the relevant information.

Categorías

Más información sobre Workspace Variables and MAT-Files en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by