Single-Line Comments

Single-line comments are comments that require only one line. They are usually drafted to explain what a single line of code does or what it is supposed to produce so that it can help someone to refer to the source code. Use % operator for adding single-line comments. This can be written in a separate line or appended to code on the same line.

Syntax :

% single line comment

Example :

MATLAB




disp("Below is the comment using %");
% this is a comment


Output :

Below is the comment using %

Comments in MATLAB

Comments are generic English sentences, mostly written in a program to explain what it does or what a piece of code is supposed to do. More specifically, information that programmer should be concerned with and it has nothing to do with the logic of the code. They are completely ignored by the compiler and are thus never reflected on to the input.

In MATLAB, comments are of two types:

  • Single-line Comments
  • Block Comments
  • Spanning MUltiple Lines

Similar Reads

Single-Line Comments

Single-line comments are comments that require only one line. They are usually drafted to explain what a single line of code does or what it is supposed to produce so that it can help someone to refer to the source code. Use % operator for adding single-line comments. This can be written in a separate line or appended to code on the same line....

Block Comments

...

Comments Spanning Multiple Lines

To make a block comment just put a ‘%{‘ in the starting of the block and ‘%}’ at the end of the block....

Contact Us