The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: oncleanup and evalin workspace
Replies: 0  

Advanced Search

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

Posts: 161
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
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)
handles.s('cat') = 3;
x = 5;
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();
% 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.


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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.