![]() To comment multiple lines you'd have to highlight them using the mouse or SHIFT. */ In Matlab this functionality can be achieved in the following way. In C or C++ we can add multi-line comments like this, /* commented code 1 commented code 2. To uncomment the selected text, click the "Uncomment" button or type "Ctrl" + "T". Alternatively, select the code and type "Ctrl" + "R". This inserts a "%" symbol in front of each selected line. Here we discuss how to provide comments in MATLAB along with the examples and outputs.To comment out a large block of code in the Editor or Live Editor, select the code and on the "Editor" or "Live Editor" tab, click the "Comment" button. Doing this prevents any run time errors from being thrown by the compiler as it does not understand human-friendly languages.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. 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. Prefix “%” at the end of the narrative lines.Our purpose is to prevent these narrative lines from getting executed by the compiler. In this example also we will be writing a dummy code with some narrative explaining the code. In the second example, we will be using our keyboard’s “%” key to comment on our narrative lines. In this example, we have used the “Comment” button present in the Live Editor for this purpose. Output 1 (After commenting on the narration lines): This is how our input and output will look like in MATLAB: ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |