How to save variables with onCleanup in Matlab? -


i have matlab script runs on cluster. if time exceeds timepoint gets killed. want use oncleanup save (or all) variables before script gets killed.

i have tried following:

function [] = test     ita = 5;     finishup = oncleanup(@() save('test.mat','ita'));     pause(7200);     disp('done')     exit end 

i thinkt variable "ita" killed before oncleanup executed, not find variable. same appears if turn function script.

ita = 5; finishup = oncleanup(@() save('test.mat','ita')); pause(7200); disp('done') exit 

how can right?

of course if use oncleanup inside function executed function stops (e.g. ctrl+c). if use script oncleanup executed when matlab exits.

i wouldn't recommend ... solution problem. set ita global use subfunction call cleanup/mat file saving. way ita in scope.

this worked when either function completed or if hit ctrl+c during pause.

function [] = test()     global ita     ita = 5;     finishup = oncleanup(@() cleanme());     pause(7200);     disp('done')  function cleanme() global ita save('test.mat','ita') 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -