


Note also that comments can be placed at the end of lines, after valid commands. Without the semicolon, every value calculated by Matlab would be immediately displayed. What it does is to suppress the echoing of the Matlab commands in the command window, so that only the desired results ( output with "disp" below ) are seen by the user. The semicolon is NOT required at the end of every Matlab statement. The Matlab "clc" command clears out the command window, which is a good thing to do at the beginning of most scripts.They should be used plentifully to make the program more readable to humans. In Matlab the % symbol signifies a comment, from the point of the % to the end of the line. More complicated programs may include a list of all the people who have worked on it, and/or a revision history documenting the important changes that have been made to the file, when, why, and by who. It is also good to include the filename in the comment, so that it will show on printouts. Every program ( in any language ) should always begin with a nice large comment, explaining what the program is all about, who wrote it, when it was written, and why.Specific lines are explained below the image:
#Ho to comment in matlab how to
Here we discuss how to provide comments in MATLAB along with the examples and outputs.The following screen shot shows a simple sample in the Matlab editor. Doing this prevents any run time errors from being thrown by the compiler as it does not understand human-friendly languages.
#Ho to comment in matlab code
Comments are used in MATLAB to provide narrative lines for the code and prevent them from getting executed.This is achieved by pressing together “Ctrl” & “R” on our keyboard Output 1 (After commenting on the narrative lines):Īs we can see in the output, the narrative lines are now commented. For this example, we will use the same code as in the above example.

#Ho to comment in matlab plus
For this, a combination of “Ctrl” plus “R” is used. In the third example, we will be using our keyboard’s shortcut keys to comment on our narrative lines. In this example, we have used the “%” key present on our keyboard. “comment” these narrative lines, to avoid any error. Therefore, we must use these lines as comments, i.e. If we try to execute our code directly, we will get a run time error in lines to lines 3 & 4 as these lines are not understandable by MATLAB’s compiler.

Let us now understand how to provide comments in MATLAB.
