How can I use string argument input as a variable name in MATLAB?
이전 댓글 표시
I'm new to MATLAB and I wanna input a string and use it as the name of a variable. How can I use string argument input as a variable name in MATLAB?
답변 (2개)
Wayne King
2013년 1월 12일
편집: Wayne King
2013년 1월 12일
Y = randn(10,10);
inputname = input('What do you want to call the matrix?\n','s');
% enter randommatrix at the command prompt
assignin('base',inputname,Y);
Now you see if you execute
>>whos
that randommatrix is a 10x10 matrix.
Jan
2013년 1월 12일
0 개 추천
It is recommended not to create variables dynamically. The commands eval and assignin are prone to bugs and impede the debugging seriously. See the related topic FAQ: How to create variables in a loop .
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!