Sorting arrays of objects by dynamic property value
이전 댓글 표시
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
Matt Moore
2016년 6월 24일
편집: Matt Moore
2016년 6월 24일
According to the Method Invocation docs the dot notation should work: "For example, the following statements are equivalent:"
obj.Property1
obj.('Property1')
If this does not work you should contact to technical support.
per isakson
2016년 6월 29일
편집: per isakson
2016년 6월 29일
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
 
Manuel
2016년 8월 1일
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
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Class Introspection and Metadata에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!