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: Use variable from different function stack
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  

Posts: 14
Registered: 12/7/04
Use variable from different function stack
Posted: Aug 22, 2017 1:52 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi all,

I'm reusing old code that in some phase generates a variable that I'd like to use in my own code. The problem is that this variable (basically a SimState from a just run Simulink simulation) is not reachable from my code because is stored in another stack. I've tried to move the variable with assignin and evalin but I've failed.

Is there any way to move from a ws to another (not necessarily 'base' and first 'caller') not in debug? I think this is not possible but maybe you can suggest some work around.

The structure of the code is the following:

% Setting the simulation to provide a snapshot of the state of the simulator at the end of the simulation
'xFinal','SaveCompleteFinalSimState','on','LoadInitialState', 'off')
% Simulation function
..existing code containing many functions and finally a

Having set the simulation as above the xFinal is stored in the workspace at the end of the simulation but this is not anymore reachable by my code (because in a different stack).
Here I would save the final state 'xFinal' to re-initialize another following simulation with the same simulator (model_1) with some changes on the initialization parameters (mass, position...).
Something like:
evalin('base', sprintf('save(''%s'',''%s'')','xFinalFile','xFinal'));

evalin('base', sprintf('load(''%s'')','xFinalFile'));

This evalin does not work because the xFinal variable is not in the base ws and I cannot modify the code when the xFinal is generated.

I hope you can understand and help.



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.