Sorting arrays of objects by dynamic property value

7 views (last 30 days)
I have an number of face images that I have loaded into an object array for presentation using Matlab. Dynamic properties for the faces are added from a spreadsheet. All objects have the same properties, but there are a lot of them.
I have found that the normal manner of searching such an array (for instance by rated Anger) does not work with the dynamic properties.
[~,idx]=sort([faceArray.Anger]);
and
[~,idx]=sort([faceArray.('Anger')]);
both return the error:
No appropriate method, property, or field 'Anger' for class 'FaceStimulus'.
I can see the field in the variable viewer, and can sort by static properties using this method. Is there something that I'm missing?
  4 Comments
per isakson
per isakson on 29 Jun 2016
Edited: per isakson on 29 Jun 2016
Did you report this "issue" to technical support? I failed to find any hint on this limitation in the documentation.
Reproduction on R2016a:
sdp = SortingDynamicProperty();
sdp(end+1) = SortingDynamicProperty();
sdp(end+1) = SortingDynamicProperty();
%
sdp(1).addprop('dyna');
sdp(2).addprop('dyna');
sdp(3).addprop('dyna');
%
sdp(1).('dyna') = 'd1';
sdp(2).('dyna') = 'd2';
sdp(3).('dyna') = 'd3';
sdp(1).A = 'A1';
sdp(2).A = 'A2';
sdp(3).A = 'A3';
>> sdp(1).('dyna')
ans =
d1
>> { sdp.('dyna') }
No appropriate method, property, or field 'dyna' for class 'SortingDynamicProperty'.
>> { sdp.A }
ans =
'A1' 'A2' 'A3'
where
classdef SortingDynamicProperty < dynamicprops
properties
A
end
end
&nbsp
Manuel
Manuel on 1 Aug 2016
It seems that what you want (I also wanted to do it... ) is not possible diretly, see: http://de.mathworks.com/help/matlab/matlab_oop/object-arrays-with-dynamic-properties.html
where it says:
MATLAB® returns an error if you try to access the dynamic properties of all array elements using this syntax.
a.DynoProp
No appropriate method, property, or field 'DynoProp' for class 'ObjectArrayDynamic'.
Refer to each object individually to access dynamic property values:
a(1).DynoProp

Sign in to comment.

Answers (0)

Categories

Find more on Properties in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!