Info

This question is closed. Reopen it to edit or answer.

findobj fails when searching dynamicprops objects

1 view (last 30 days)
William Young
William Young on 21 Jun 2011
Closed: MATLAB Answer Bot on 20 Aug 2021
Greetings and thanks in advance for any suggestions.
I am having a problem using findobj with objects containing dynamic properties. Here's a simple case.
Given this class definition:
classdef myDynamicClass < dynamicprops
properties
normalProperty
end
methods
function obj = myDynamicClass(value)
if nargin > 0
obj.normalProperty = value;
end
end
end
end
and some setup code:
v = myDynamicClass(1);
v(2) = myDynamicClass(2);
addprop(v(1), 'dynamicProperty');
v(1).dynamicProperty = 'kPa';
addprop(v(2), 'dynamicProperty');
v(2).dynamicProperty = 'psi';
Now, I can use findobj successfully to search on the normal property
>> findobj(v, 'normalProperty', 2)
ans =
myDynamicClass handle
Properties:
normalProperty: 2
dynamicProperty: 'psi'
Methods, Events, Superclasses
However, when I do the same on the dynamic property, the result is either all or none of the objects passed in:
>> findobj(v, 'dynamicProperty', 'kPa')
ans =
2x1 myDynamicClass handle
Properties:
normalProperty
Methods, Events, Superclasses
>> findobj(v, 'dynamicProperty', 'psi')
ans =
0x0 empty myDynamicClass handle
Properties:
normalProperty
Methods, Events, Superclasses
What's going on here? Am I doing something wrong? The documentation (section "Finding Objects Having Specific Settings") conveniently doesn't use findobj on dynamic properties in this way.

Answers (1)

Walter Roberson
Walter Roberson on 22 Jun 2011
I do not know about such things, but the documentation indicates that findprop could be used
findprop(v,'psi')
findprop() is specifically documented as working with dynamic properties. It is not, however, documented as working with object arrays.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!