{ }
Name: Curly brackets
Uses: Cell array assignment and contents
Description: Use curly braces to construct a cell array, or to access the contents of a
particular cell in a cell array.
Examples
To construct a cell array, enclose all elements of the array in curly braces:
C = {[2.6 4.7 3.9], rand(8)*6, 'C. Coolidge'}
Index to a specific cell array element by enclosing all indices in curly braces:
A = C{4,7,2}
More Information
• “Cell Arrays”
%
Name: Percent
Uses:
• Comment
• Conversion specifier
Description: The percent sign is most commonly used to indicate nonexecutable text
within the body of a program. This text is normally used to include comments in your
code.
Some functions also interpret the percent sign as a conversion specifier.
Two percent signs, %%, serve as a cell delimiter as described in “Create and Run Sections
in Code” on page 18-5.
Examples
Add a comment to a block of code:
% The purpose of this loop is to compute
% the value of ...
Use conversion specifier with sprintf:
sprintf('%s = %d', name, value)
More Information
• “Add Comments to Code” on page 18-3
MATLAB Operators and Special Characters
2-11
Name: Curly brackets
Uses: Cell array assignment and contents
Description: Use curly braces to construct a cell array, or to access the contents of a
particular cell in a cell array.
Examples
To construct a cell array, enclose all elements of the array in curly braces:
C = {[2.6 4.7 3.9], rand(8)*6, 'C. Coolidge'}
Index to a specific cell array element by enclosing all indices in curly braces:
A = C{4,7,2}
More Information
• “Cell Arrays”
%
Name: Percent
Uses:
• Comment
• Conversion specifier
Description: The percent sign is most commonly used to indicate nonexecutable text
within the body of a program. This text is normally used to include comments in your
code.
Some functions also interpret the percent sign as a conversion specifier.
Two percent signs, %%, serve as a cell delimiter as described in “Create and Run Sections
in Code” on page 18-5.
Examples
Add a comment to a block of code:
% The purpose of this loop is to compute
% the value of ...
Use conversion specifier with sprintf:
sprintf('%s = %d', name, value)
More Information
• “Add Comments to Code” on page 18-3
MATLAB Operators and Special Characters
2-11
