How can I use string argument input as a variable name in MATLAB?

5 vues (au cours des 30 derniers jours)
Behnam
Behnam le 12 Jan 2013
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?

Réponses (2)

Wayne King
Wayne King le 12 Jan 2013
Modifié(e) : Wayne King le 12 Jan 2013
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 le 12 Jan 2013
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 .

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by