MATLAB Object-Oriented Programming

(Joyce) #1

MATLAB Code Analyzer Warnings


In this section...
“Syntax Warnings and Property Names” on page 5-34
“Variable/Property Name Conflict Warnings” on page 5-34
“Exception to Variable/Property Name Rule” on page 5-35

Syntax Warnings and Property Names


The MATLAB Code Analyzer helps you optimize your code and avoid syntax errors while
you write code. It is useful to understand some of the rules that the Code Analyzer applies
in its analysis of class definition code. This understanding helps you avoid situations in
which MATLAB allows code that is undesirable.

Variable/Property Name Conflict Warnings


The Code Analyzer warns about the use of variable names in methods that match the
names of properties. For example, suppose a class defines a property called
EmployeeName and in this class, there is a method that uses EmployeeName as a
variable:

properties
EmployeeName
end
methods
function someMethod(obj,n)
EmployeeName = n;
end
end

While the previous function is legal MATLAB code, it results in Code Analyzer warnings
for two reasons:


  • The value of EmployeeName is never used

  • EmployeeName is the name of a property that is used as a variable


If the function someMethod contained the following statement instead:

obj.EmployeeName = n;

5 Class Definition—Syntax Reference

Free download pdf