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

조회 수: 1 (최근 30일)
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'.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2009년 6월 27일
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;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calendar에 대해 자세히 알아보기

제품


릴리스

R14SP1

Community Treasure Hunt

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

Start Hunting!

Translated by