Section 1.6 Comments and sections in a script
Any text after percent sign %
is treated as a comment. A comment can appear on its own line or at the end of a line with code.
a = 3; % let's increase a by 1 a = a + 1; % now a is equal to 4
A line that begins with two percent signs %%
begins a new section of Matlab script:
%% problem 1 disp(log(pi)) % the natural logarithm of pi %% problem 2 disp(log10(pi)) % the base-10 logarithm of pi
Clicking “Run” or pressing F5 runs the entire script. But clicking “Run Section” or pressing Ctrl+Enter runs only the current selection.
For Octave users: currently Octave does not have “Run Section” but it has “Run Selection” (F9) which executes the currently selected part of code.