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
Wayne King 2013 年 1 月 12 日
編集済み: Wayne King 2013 年 1 月 12 日

0 投票

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
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 ExchangeCharacters and Strings についてさらに検索

タグ

タグが未入力です。

質問済み:

2013 年 1 月 12 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by