Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: oncleanup and evalin workspace
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
question on Lorenz equation

Posts: 159
Registered: 12/7/04
oncleanup and evalin workspace
Posted: Aug 13, 2014 1:57 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

1. First let me tell you this weird behavior. I have these two functions in one file, test_evalin.m.

% begin
function test_evalin
onCleanup(@()cleanup);
x = 7
y = 3

function cleanup
evalin('caller', 'whos')
% end

It returns that both x and y are in the workspace. But if I add semi-colons to the end of the assignment lines (i.e. "x=7;"), then it returns that there are no variables in the workspace. For some reason, adding a semi-colon makes it not show up. Can anyone else confirm this behavior? And is it a bug, or does it make sense to you?

2. Ultimately, what I want to do is have my function give one value if it terminates with a Ctrl-C and another if it terminates normally. Here's my new sample code:

% begin
function testf(handles)
onCleanup(@()cleanup);
handles.s('cat') = 3;
x = 5;
pause(3);
x = 7;

function cleanup
handles = evalin('caller', 'handles');
x = evalin('caller', 'x');
handles.s('dog') = x;
% end

I call it like this:
% begin
handles = struct;
handles.s = containers.Map();
testf(handles);
values(handles.s)
% end

So if it gets through the pause, x will be 7, and the cleanup function will assign that to the map. Otherwise, the old value of 5 will be assigned. This exhibits the same problem with the semi-colon as above. However, more broadly on my objective, does this look like a good approach? Or is there a better way to achieve this dichotomous behavior for when Ctrl-C happens.

Thanks!



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.