use strings to give commands
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Daniel Shub
2011-9-23
how about replacing
load('blabla.mat', str);
with
data = load('blabla.mat', str);
Then the variable can be accessed with
data.(str)
0 个评论
更多回答(1 个)
Olli
2011-9-24
1 个评论
Fangjun Jiang
2011-9-24
Then, please accept the answer! I think this is a good solution and could be referenced by others.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!