use string as a cell array.
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi:
I have various variables in the workspace: january_ns=1, february_ns=2, march_ns=3,.... Also I have an array like this: month={january february march }
I would like to show the content of the variable january_ns for example but using the array to show it.
To write month{1}_ns instead january_ns to show the value 1, for example.
I was trying with the next line, but it didnt work.
([month{1},'_ns',''])
Any idea to do that? Thanks.
댓글 수: 0
채택된 답변
Anthony
2013년 10월 18일
january_ns=1, february_ns=2, march_ns=3
month={'january' 'february' 'march' };
eval([month{1},'_ns'])
댓글 수: 2
추가 답변 (1개)
Azzi Abdelmalek
2013년 10월 18일
편집: Azzi Abdelmalek
2013년 10월 18일
month={'january' 'february' 'march' }
month{1}
month{2}
% You don't need to create a variable january_ns. Can you explain why you want to create these variables?
댓글 수: 4
Jan
2013년 10월 18일
+1: This solution is much better than the eval approach. It is a bad programming practice to store important information in the name of variables, because carrying values is a job for the contents of a variable, not for the name!
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!