Does anyone know that there can be a heap of workspaces in MATLAB? It would be very convenient, to say the least.
I need this for research. We have several scripts that interact interestingly. Functions are local variables, but there is no script ...
The regular metallab function call stack is a stack, the easiest way to use one's workspace function, and copy-on-written of Matlab makes it appropriately efficient but perhaps it Not what you are asking for.
There is a natural correspondence between workspace and strokes because the same identifiers are valid for variable names and structures fields. They are essentially both identifier => Mxarray mapping.
You can use whos
and evalin
to capture a workspace position for a structure. Use a cell vector to apply one of those stacks. (A straight array will not work because it requires homogeneous field names.) Stacks can be stored in the appadata to prevent it from appearing in a workspace.
Here are push and pop functions for this technique
function push_workspace () c = getappdata (0, 'WORKSPACE_STACK'); If Hamperity (C) C = {}; The end% hold the workspace w = evalin ('collar', 'whos'); Name = {w.name}; S = struct; I for = 1: numel (w) s (Names {i}) = evalin ('caller', names {i}); Push it to end% stack C {And + 1} = S; Setappdata (0, 'WORKSPACE_STACK', c); Function pop_workspace ()% off previous workstation stack C = getappdata (0, 'WORKSPACE_STACK') pop; If direct (C) warning ('nothing on the workstation stack'); Return; End s = c {end}; C (end) = []; Setappdata (0, 'WORKSPACE_STACK', c); % If you want a blank slate for your workspace evalin ('collar', 'clear'), do it; Caller's workspace names =% stick wars in field names; I for = 1: number (name) assignine ('caller', name {i}, s (name {i}); End
No comments:
Post a Comment