Matlab: Transfer variable from GUI to Base Workspace and new Variables (Static Workspace, Script, Creating new Variables) -
I am developing a GUI for the current script, which expects some straight values in the base workspace. The GUI will move users' values to the base-workspace and then the script will start and close itself immediately. It sounds very easy and has values that run with Essenin and Evelyn, but I work for days with the problem that if the script takes the values of my post, then I get a message: < P> Try to add var_name View MATLAB programming for static workspace details, see restrictions on assigning at variables. What's the problem? The GUI is closed and the script will use the base-workspace without restriction. How can this be done? The script is untouchable (not mine) and this base expects variables in the workspace, so the GUI is moving the value in the workspace and nothing else. A stable workspace is not required Workspaces will be free of any restrictions. To summarize: I want to delete "Static" in the "static workspace" Specifies the MATLAB documentation That: If you dynamically try to dynamic a variable in the workspace of a nested function in an anonymous function, nested function, or a function, then causes an error is. Therefore, your problem most likely results from calling a script from an anonymous callback of some buttons in your GUI (I can guess without any details). If this is the case, then wrap it in the another function, so that you can isolate the variable created by the script from the Anon Function workspace. Design the Rubber Function Accept the arguments of those variables that you want to reach the script, so that's what the script will need. Also, make sure that you do not work nesting inside your cover because you will get the same problems. Note: What do you expect, a script will not create its variables in the base workspace called by function, but in the workspace of the function If called from another script, then it will use the base workspace for the variable creation. Example: Suppose the script "his_script.m" has variable Because nobody is and the work logic will work as the input for the script, the return value of the function will be output to scripts. Now you can use your call to wrapper functions in an anonymous callback of a button, for example: I hope this idea is now clear. Please tell me how it works for you. Further comment: One of the main differences between scripts and functions is that scripts do not have their own workspace, while the works are scripts use the workspace of those instances Who call them This means that your target is misleading "GUIs should be transferred to workspace and anything else" is misleading because you do not know where the workspace is for the script, as long as That you do not say it in the first place. If you want to write the actually GUI in the base workspace, you do this, but you should manually call your script from the console window, because the console The reference to the window is the base workspace or try to use
invar1 and
invar2 already in your accessible workspace Are in; The output of the script (i.e. created variable) variable
outvar3 and
outvar4 :
% his_script.m outvar3 = invar1 + invar2; Outvar4 = invar1 - invar2;
assigned and
evalin we wrap it in a function
my_wrapper.m %
% my_wrapper.m function [outvar3, outvar4] = my_wrapper (invar1, invar2)% If the script can not be pledged with% hands on the holy book of the execution path, then output Make% all output variables will be created Outvar3 = []; Outvar4 = []; % Script his_script;
% your GUI% installs ... .. Set (action_button_handle, 'callback', action_button_callback); % ... is deeper in your GUI code, nested function for% script function action_button_callback (hObject, callbackdata) [out1, out2] = my_wrapper (5,3); Display (out1); Display (out2); End% ...
evalin ('base', 'script_name;'); But you need to test (so far I resisted the temptation to use stuff like this - really easy to mess up, and I do not want to curse me).
Comments
Post a Comment