Main Content

percent, %

Code comments, conversion specifier

Syntax

Description

The percent symbol (%) indicates nonexecutable text within the body of a program, and some functions also interpret the percent symbol as a conversion specifier. For instance, % Code comment uses a percent symbol to indicate a nonexecutable text comment in a program.

example

Examples

expand all

Use a % symbol in a line of code to add a code comment. Any text that appears after the % symbol on that line is nonexecutable.

a = [1 2 3];
% This line is a code comment, and you can
% extend comments to multiple lines.
b = a.^2;

Use the sprintf function to replace a string and decimal number with input values. The sprintf function interprets the percent symbol as a conversion specifier.

A = 1;
sprintf("%s = %d","Index",A)
ans = 
"Index = 1"

Version History

Introduced before R2006a