Main Content

isprop

Determine if property is defined by object

Description

example

tf = isprop(obj,PropertyName) returns logical 1 (true) if the specified PropertyName is a property of object obj. Otherwise, isprop returns 0 (false). If obj is an array, isprop returns a logical array the same size as obj. Each true element of tf corresponds to an element of obj that has the property PropertyName.

Examples

collapse all

You can verify the existence of a property of an object before attempting to set it by using isprop in an if-statement.

Create a line plot and assign a variable to the object.

p = plot(1:10,1:10);

Graph of a solid line

Use an if-statement to verify that object p has the LineStyle property. If it does, then set a new value for LineStyle.

if isprop(p,"LineStyle")
  p.LineStyle = ":";
else
  disp("This object does not have a LineStyle property.")
end

Graph of a dotted line

Input Arguments

collapse all

Object to investigate, specified as a single object or an object array.

Name of property, specified as a character vector or string scalar.

Limitations

  • Classes can control access to property values by defining property attributes. For example, a property can be private, which means it is readable and writable only inside the class that defines it. isprop indicates that these properties exist regardless of whether you have direct access to that property. For more information, see Property Attributes.

  • isprop always returns false when called with any value type of PropertyName other than a character vector or string scalar. For example, if you pass in a string array for PropertyName, isprop returns false even if one or more of the array elements are properties of the object.

  • If obj is an empty object or an array of empty objects, isprop returns an empty logical array, even if PropertyName is a property of obj.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced before R2006a