use strings to give commands

4 Ansichten (letzte 30 Tage)
Olli
Olli am 23 Sep. 2011
Hi everyone,
I have many variables with different names and they all content a struct "Value". Now a program loads one of those variables in my workspace, only knowing by a string which one it is.
For example: str='xxx'; load('blabla.mat', str);
Now I want to get access to xxx.Value and I want to ask you, how I can get that command when I only have 'xxx' as a string?
As I told you, the program must being kept general, because xxx can stand for any of many variables.
Best regards and thank you! Oli

Akzeptierte Antwort

Daniel Shub
Daniel Shub am 23 Sep. 2011
how about replacing
load('blabla.mat', str);
with
data = load('blabla.mat', str);
Then the variable can be accessed with
data.(str)

Weitere Antworten (1)

Olli
Olli am 24 Sep. 2011
That's a good idea, thanks a lot! Now it works :-).
  1 Kommentar
Fangjun Jiang
Fangjun Jiang am 24 Sep. 2011
Then, please accept the answer! I think this is a good solution and could be referenced by others.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Characters and Strings 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