test_hnf2.m (168 Bytes)
As discussed in the online meeting today, here’s an example function that can be used to demonstrate the way handles to nested functions share call stack frames and how that should work even after saving and reloading the handles.
Try the following:
[fh1, fh2] = test_hnf2 (); %% create handles to nested functions fh2 () %% should display captured value ==> 1 fh1 () %% increment and display ==> 2 fh1 () %% again ==> 3 fh2 () %% display ==> 3 [fha, fhb] = test_hnf2 (); %% independent set of handles fhb () %% note that the values shared belong to the fha () %% stack frames active when the handles ...
Octave can’t save these objects yet but if you save them in Matlab then clear all and reload them, you should be able to continue execution from the point where you saved them:
save nested-handles.mat fh1 fh2 clear all %% or start a new session load nested-handles.mat fh2 () %% display ==> 3 fh1 () %% increment and display ==> 4 ...
One question that came up in the meeting was what Matlab file formats can be used to save handles to nested functions. I expect only
-v7.3, but could someone try saving them using
-v4? I expect failures with all of these, but just to be sure…
save nested-handles-v7-3.mat fh1 fh2 -v7.3 save nested-handles-v7.mat fh1 fh2 -v7 save nested-handles-v6.mat fh1 fh2 -v6 save nested-handles-v4.mat fh1 fh2 -v4