Why do I receive an error when I run the example code in the help documentation page titled "Using Dynamic Field Names"?

1 vue (au cours des 30 derniers jours)
The example code in the help documentation page under "MATLAB -> Programming -> Data Types -> Structures -> Using Dynamic Field Names" seems to show that structures can have field names with spaces in them. However, when I try to create a structure with a dynamic field name that contains a space, I receive an error message:
str = 'Ann Lane';
x.(str) = 5;
??? Invalid field name: 'Ann Lane'.

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 27 Juin 2009
This bug has been fixed in Release 14 Service Pack 2 (R14SP2). For previous releases, please read below for any possible workarounds:
We have verified that there is an error in the documentation for dynamic field names, in that the names of structure fields cannot have spaces. As a workaround, use 'Ann_Lane' and 'William_King' as the dynamic field names, instead of 'Ann Lane' and 'William King':
str = 'Ann_Lane';
x.(str) = 5;

Plus de réponses (0)

Catégories

En savoir plus sur Calendar dans Help Center et File Exchange

Produits


Version

R14SP1

Community Treasure Hunt

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

Start Hunting!

Translated by