Filter löschen
Filter löschen

Load

2 Ansichten (letzte 30 Tage)
john
john am 11 Apr. 2012
Hi,
If I write in command window "load a", then in workspace will appears variable "a". If I write "load a" in GUI code, so in workspace will apears nothing but variable "a" is available for GUI code. Why? Why is it not appears in workspace and why is available for GUI?
Thank you
  1 Kommentar
Daniel Shub
Daniel Shub am 11 Apr. 2012
Loading a mat file, or a set of mat files, from a gui or function and poofing variables into the base workspace might be a case where I would be willing to use evalin, I doubt it, but maybe.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 11 Apr. 2012
Please read the Getting Started chapters of the documentation. There you find the explanation, that each function has its own workspace - a kind of container for the local variables - to avoid interferences. The command load imports the contents of the file in the current workspace, such that it appears in the base workspace, when it runs in the command windows. But when load is called inside a function, the imported variables are available only there. And this is important and safe.
To reduce confusions and unwanted side-effects it is recommended to store the output of load in a variable:
Data = load(FileName);
Then using Data.a shows directly, where the value is comming from. But in:
a = 3.1415;
load(FileName); % NOT CLEAN!
disp(a);
Now it is impossible to know the source of the value of a when reading the source code. This makes the debugging much harder.
  6 Kommentare
john
john am 11 Apr. 2012
great code for me :), how do you know this?. I didn't find "save(fullfile(PathName, FileName), 'Data');" in matlab help.
.
.
.
can you help me with loading of variable ( this means with uigetfile and with load) ? please
john
john am 11 Apr. 2012
I made loading for variable...so big thank you again

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Use COM Objects in MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by