String to Variable conversion?
이전 댓글 표시
So first I declare some variables:
data.variable=12
v1='variable'
n=1
The results:
strcat('data.', v1)
data.variable
But
strcat('data.', (strcat('v',num2str(n))))
data.v1
Instead of data.variable. I'm assuming that this is because v1 is a string. What should I do to make the second command return data.variable?
채택된 답변
추가 답변 (2개)
Evgeny Pr
2013년 1월 24일
So that's that?
strcat('data.', evalin('base', strcat('v',num2str(n))))
Azzi Abdelmalek
2013년 1월 24일
Why are n't you using one array to save your variables, instead of using, v1,v2,...
For example
data.variable1=10;
variable={'variable1','variable2','variable3'}
out=data.(variable{1})
카테고리
도움말 센터 및 File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!