Why is the order of child handles reversed when an object is queried for the 'Children' property?

21 次查看(过去 30 天)
When multiple children are added to a graphics object such as a figure or an axes, the order of the child handles is reversed in the 'Children' property as compared to the order in which those children were added.
For example, if I create an axes and make two line plots on it, I expect the handle of the first line plot to appear before the handle of the second line plot when I query for the 'Children' property using the GET function. Instead this order is reversed.
>> figure
>> h = axes;
>> h1 = plot(1:10, 1:10, 'b')
h1 =
158.0044
>> hold on
>> h2 = plot(1:10, 2:2:20, 'r')
h2 =
159.0039
>> get(gca, 'children')
ans =
159.0039
158.0044
As can be seen above, the order of child handles is the opposite of the order in which they were added to the axes.

采纳的回答

MathWorks Support Team
The behavior that is observed here is not a bug but instead a design decision which causes the most recently added child object's handle to appear at the top of the list of handles returned by the 'Children' property. This behavior can be observed in a variety of cases presently in MATLAB as follows:
1. Adding multiple line objects to an axes
2. Adding multiple uicontrols to a figure (uicontrols are children of the figure object)
3. Adding multiple axes to a figure (axes are children of the figure object)
  1 个评论
Walter Roberson
Walter Roberson 2020-8-14
Is the order of the child objects preserved under saving figures and copying objects?
Yes, for both.
Can this order be changed?
uistack() is the interface for that. However you can also just set the parent's Children property to a re-ordered list of the Children, as long as it is a permutation of the existing children.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by