exception handling - How can I pass data to the MATLAB oncleanup function? -
I have a compiled matlab program that automatically tunes the machine parameter. At the end of a tuning cycle I need to restore some basic settings. I have unexpected errors at some time and sometimes the user can see that the tuning algorithm is not working properly, so it should be finished Should (with control-C)
If there is an approximate error, then I try to hold a block. However, if there is an unexpected error or the user invokes Control-C, then the program goes out without passing, although the hold segment and the machine are left in an undetermined position.
I know that I will run a cleanup function as the function of my work, either in general or by an unexpected error, or Control-C event. Ideally, clean work functions can not do anything and if there is an estimated error, then there is a control over the top level to clean it. If there is a control-cum-event or an unexpected error, then clear that the user should warn that the program has failed so that it can be cleaned manually.
To do this, I need to make the fact of the prediction or not anticipated termination (i.e. control-c), which is clearly known at the time of running. I know that the cleanup function takes a copy of the parameter values when it is registered, and that can not be changed at run time, so passing through a parameter can not work. I believe that should work my work The cleanup function within the function is to function as nest, so that the local variable in the attached function is available for clean function. It does not work though.
My question is, can anyone make available only a bullion to do a clean job, so that he can choose between normal and unusual cleaning?
Here are some shoddy examples that should work the code which I believe should be.
function do_tuning% Set-wrong due to a warning message for Control-C or MATLAB coding errors. General determination = false; Oc = onCleanup (@ () my_clean_up ()); TuningError = tuning_function () If tuning error% set this true to press the warning message, if an inaccurate error occurs. General idea = true; If the error ('tuning error') runs until the end% function is complete, set it to correct the warning message. General idea = true; Function my_clean_up if ~ General Refinement Disp ('Warning: Cleared, Please Manually Clean'); End of End The actual code execution error after this pattern causes the error:
Undefined function or variable "Generation Generation"
onCleanup calls the object function outside the scope of the field do_tuning Using a nested function of the function will not help ... In fact, documetation says:
[edit - based on comments] A better The solution will be to change the problem and clean the all within the my_clean_up function, for which it may be necessary to determine what needs to be done (or can always be applied for normal behavior) If we neglect this warning and solve the question ...
For the example code given above, it is easy to pass the variable between workspaces. First, global first defines a variable by setting it to false form (otherwise the variable can be overwritten) function do_tuning% # snip global generalTermination NormalTermination = false; function Second, the my_clean_up callback function defines the variable in the variable first of the global variable As usual - my_clean_up Global General Turning If ~ General Termination% # Trash Warning This global variable is being edited elsewhere at the wrong time is .
Comments
Post a Comment