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

1 view (last 30 days)
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'.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 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;

More Answers (0)

Products


Release

R14SP1

Community Treasure Hunt

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

Start Hunting!