Create variables in active workspace from script

7 次查看(过去 30 天)
Hello - I have a script which sets values to a range of variables, prior to running a GUI which calls on those variables.
The problem, however, is that the GUI requires the variables to be active in the workspace; rather than set in the background of a script. If I open the Script Editor, and run the script; it outputs variables into the workspace, whereas if I run the script via its command, it does not.
So, when I run the GUI; hoping to publish the values in those variables, I get this error:-
??? Error using ==> evalin
Undefined function or variable 'LForce'.
Error in ==> ffcgps>ffcgps_OpeningFcn at 57
LForce = evalin('base', 'LForce');
As an example. In other words, as the value isn't in the workspace, for some reason, evalin will not work.
Any assistance to automate this would be very helpful.
Thank you in advance.

回答(1 个)

Jan
Jan 2013-7-30
This sounds like a wildly distributed organization of variables. It is very prone to errors if you pick the variables from different workspaces. Using inputs and outputs is much cleaner.
It is hard to give an explicit answer, because your question is vague only. Please note that the meaning of "sets values to a range of variables, prior to running a GUI which calls on those variables" is clear to you, but nobody else here knows, what you are exactly doing. The term "active in the workspace" might have a distinct meaning, but each function has its own workspace and the worspaces of other functions are gone, when they they return to their callers.
  2 个评论
Nicolas Hart
Nicolas Hart 2013-7-30
Thank you for your response. Apologies for my lack of clarity, or appropriate use of terminology.
In relation to your final statement concerning functions with their own workspace. I remember, when reading the help files (to try and solve this myself first), there was a function available to make variables "global". I presumed this would allow me to call on those variables using other functions (ie: transcend across workspaces). Is that achievable?
Jan
Jan 2013-7-30
The command global allows to access the corresponding variables globally. But this is considered as a bad programming practice which make the programming and debugging much harder and if the code grows with the time you reach a point, where maintenance is not possible anymore.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT Files 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by