Programming

Percent -- %

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.

Precede any one-line comments in your code with a percent sign. MATLAB does not execute anything that follows a percent sign (that is, unless the sign is quoted, `'%'`):

• ```% The purpose of this routine is to compute
% the value of ...
```

Conversion Specifiers

Some functions, like `sscanf` and `sprintf`, precede conversion specifiers with the percent sign:

• ```sprintf('%s = %d', name, value)
```

Percent-Brace -- %{ %}

The `%{` and `%}` symbols enclose a block of comments that extend beyond one line.

Enclose any multiline comments with percent followed by an opening or closing brace.

• ```%{
The purpose of this routine is to compute
the value of ...
%}
```

 Note    The `%{` and `%}` operators must appear alone on the lines that immediately precede and follow the block of help text. Do not include any other text on these lines.

Semicolon -- ;

The semicolon cnn be used to construct arrays, supress output from a MATLAB command, or to separate commands entered on the same line.

Array Row Separator

When used within square brackets to create a new array or concatenate existing arrays, the semicolon creates a new row in the array:

• ``````A = [5, 8; 3, 4]
``````A =
``````     5     8
``````     3     4
``````

Output Suppression

When placed at the end of a command, the semicolon tells MATLAB not to display any output from that command. In this example, MATLAB does not display the resulting 100-by-100 matrix:

• ```A = ones(100, 100);
```

Command or Statement Separator

Like the comma operator, you can enter more than one MATLAB command on a line by separating each command with a semicolon. MATLAB suppresses output for those commands terminated with a semicolon, and displays the output for commands terminated with a comma.

In this example, assignments to variables `A` and `C` are terminated with a semicolon, and thus do not display. Because the assignment to `B` is comma-terminated, the output of this one command is displayed:

• ```A = 12.5;  B = 42.7,  C = 1.25;
B =
42.7000
```

Single Quotes -- ' '

Single quotes are the constructor symbol for MATLAB character arrays.

Character and String Constructor

MATLAB constructs a character array from all characters enclosed in single quotes. If only one character is in quotes, then MATLAB constructs a 1-by-1 array:

• ```S = 'Hello World'
```