
M-Lint Code Check Report
Message — Code (Original Line Numbers)
Explanation and Updated Code (New
Line Numbers)
34: 'data' might be growing inside
a loop. Consider preallocating for
speed.
—————————————————
33 for nd = 1:length(fdata)
34 data{nd} = getfield(flds,fdata{nd});
See the same message and explanation
reported for line 24. Add this line, 34, b efore
the loop
data = cell(size(fdata));
34: Use dynamic fieldnames with
structures instead of GETFIELD. Type
'doc struct' for more information.
—————————————————
34 data{nd} = getfield(flds,fdata{nd});
You can access a f ield in a structure as a
variable expression that MATLAB evaluates
at run-time. This is more efficient than using
getfield. For more information, type doc
struct
to see the reference page for structures,
or see “Using Dynamic Field Names” in
the MATLAB Programming documentation.
Change line 37 to
data{nd} = flds.(fdata{nd});
38: Use || instead of | as the OR
operator in (scalar) conditional
statements.
39: Use || instead of | as the OR
operator in (scalar) conditional
statements.
40: Use || instead of | as the OR
operator in (scalar) conditional
statements.
—————————————————
38 if isempty(data{3}) | ...
39 (length(unique(data{1}(:)))==1 | ...
40 length(unique(data{2}(:)))==1 | ...
41 length(unique(data{3}(:)))==1)
While | (the element-wise lo gical OR operator)
performs the com paris on correctly, use the ||
(short circuit
OR operator) for efficiency. For
details, see “Logical Operators” i n the MATLAB
Programming documentation. Change lines
40, 4 1, and 42 to
if isempty(data{3}) || ...
(length(unique(data{1}(:)))==1 || ...
length(unique(data{2}(:)))==1 || ...
7-23
Komentáře k této Příručce