Create variables in active workspace from script

조회 수: 7 (최근 30일)
Nicolas Hart
Nicolas Hart 2013년 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