The purpose of layout is to help the reader understand the code. Indentation is particularly helpful for revealing structure.
Files that are shared between several people should keep within these constraints. Readability improves if unintentional line breaks are avoided when passing a file between programmers. Seventy five columns is the MATLAB editor default, so keeping within 75 columns will ensure compatibility with most other users if your organization doesn't have a standard.
Split lines occur when a statement exceeds the suggested 80 column limit.
In general:
totalSum = a + b + c + …
d + e;
function (param1, param2,…
param3)
setText ([‘Long line split’ …
‘into two parts.’]);
Good indentation is probably the single best way to reveal program structure.
Indentation of 1 is too small to emphasize the logical layout of the code. Indentation of 2 is sometimes suggested to reduce the number of line breaks required to stay within 80 columns for nested statements, but MATLAB is usually not deeply nested. Indentation larger than 4 can make nested code difficult to read since it increases the chance that the lines must be split. Indentation of 4 is the current default in the MATLAB editor; 3 was the default in some previous versions.
The MATLAB editor provides indentation that clarifies code structure and is consistent with recommended practices for C++ and Java.
This practice improves readability and allows JIT acceleration.
This practice is more compact, but it has the disadvantage that there is no indentation format cue.
if(condition); statement; end
while(condition); statement; end
for iTest = 1:nTest; statement; end