use strings to give commands
조회 수: 6 (최근 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!