how to make a variable name from a string
Afficher commentaires plus anciens
2013a version
>> test='eye'
>> value = [5,5,3]
value =
5 5 3
>> eval([sprintf(test) '= data+1']);
Index exceeds matrix dimensions.
How to fix this error? Thank you for helping!
Réponse acceptée
Plus de réponses (3)
xianghong
le 16 Août 2013
0 votes
1 commentaire
Walter Roberson
le 16 Août 2013
No, it is not just for creating field names within a variable. It shows a number of different alternatives to creating a variable from a string, recommending strongly that you use one of the alternatives instead of creating a variable dynamically. At the end of the FAQ it shows how to create a variable dynamically, for the rare case when you really need to do that. If you are not engaged in creating extensions to MATLAB itself, chances are that there is a better route than creating a variable dynamically.
xianghong
le 16 Août 2013
0 votes
2 commentaires
Walter Roberson
le 16 Août 2013
Please use the command
clear eval
and then try again
xianghong
le 19 Août 2013
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!