ID LAYOUT-3
Title Surround operators with spaces.
Priority Recommended
Severity level 9
Description Surround the following operators with spaces: = : ^ == <= >= < > ~= & &&
| || + - * .* /
Do not add a space between the unary minus-sign and its operand.
Rationale Whitespace around operators often leads to improved readability. As an exception, do not use spaces around the equals signs when using the Name=Value
syntax introduced in MATLAB R2021a.
isValid=y>0&&x==-1;
isValid = y > 0 && x == -1;
ID LAYOUT-4
Title Commas, semicolons and keywords shall be followed by a space unless at the end of the statement.
Priority Recommended
Severity level 9
Description Commas, semicolons and keywords (for
, while
, if
etc.) shall be followed by a space unless at the end of the statement.
Rationale A clear separation of keywords from other code improves readability.
while(ismember(x, [3,5,7,11,13]))
x = x + 2;
end
while ismember(x, [3, 5, 7, 11, 13])
x = x + 2;
end
ID LAYOUT-12
Title Do not use whitespace at the end of a line.
Priority Recommended
Severity level 9
Description To keep things clean, do not use white space at the end of a line of code unless it is followed by a comment.
Rationale This prevents smart-indenting a file from inducing changes to those lines.
ID LAYOUT-16
Title Separate blocks of code by one or more blank lines.
Priority Recommended
Severity level 9
Description Separate coherent blocks of code by one or more blank lines.
Rationale Increases the readability of the code.
deltaX = mean(xIn);
xOut = xIn - deltaX;
scalingFactor = newZ / currentZ;
xOut = xOut .* scalingFactor;
xOut = xOut + deltaX;
% Shift to origin.
deltaX = mean(xIn);
xOut = xIn - deltaX;
% Calculate scaling.
scalingFactor = newZ / currentZ;
xOut = xOut .* scalingFactor;
% Shift back.
xOut = xOut + deltaX;