text object array being reversed when retrieved from handle

3 views (last 30 days)
I am building a GUI where I am trying to plot an hexagonal matrix and number each hexagon (see attachment).
I used the patch function to plot the hexagons and then used the "text" function with a number array to place the numbers. I want to process now the numeration of the hexagons, and the order of the numbers is important. The problem is that the TEXT object array is reversed when I retrieved it from guihandles.
I reproduced the problem with a simple figure object, since my GUI is too complex:
FIG = figure
AXES = axes(FIG)
x = [0.25, 0.5, 0.25, 0.5];
y = [0.25, 0.25, .5 0.5];
str = {'1', '2', '3', '4'};
T = text(AXES, x, y, str, 'tag', 'T');
T1 = {T.String};
h = guihandles(FIG);
T2 = {h.T.String};
[T1', T2']
The output is:
ans =
4×2 cell array
{'1'} {'4'}
{'2'} {'3'}
{'3'} {'2'}
{'4'} {'1'}
I want both columns to go in ascending order. So I updated the handle trying to correct the situation, but no use:
h.T = fliplr(h.T);
T3 = {h.T.String};
set(h.T, 'Tag', 'T_updated');
h2 = guihandles(FIG);
T4 = {h2.T_updated.String};
[T3', T4']
Output:
ans =
4×2 cell array
{'1'} {'4'}
{'2'} {'3'}
{'3'} {'2'}
{'4'} {'1'}
Notice that T3 is reversed compared to T2 as suposed, but then when I retrieve the handle again to T4, it has again the wrong order.
The question is: why is the second column flipped compared to the first? Is there any way to manipulate the handle to correct this, without having to use the fliplr function everytime I retrieve the handle? Also notice that the figure display is unaffected by these operations, so I suspect MATLAB automatically reorders the TEXT object array.
Thanks for any insight.
  2 Comments
Jan
Jan on 16 Mar 2018
The relevant parts of your code are not posted. How and where is h.TEXT defined? How did you try to "update the TEXT handle with the fliped version"?
André
André on 16 Mar 2018
Edited: André on 16 Mar 2018
I didn't post because the GUI is extremely more complex than what is the scope of this question, but I can reproduce the problem very briefly, so I updated the main post and it is more understandable now.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 16 Mar 2018
The text() call returns handles in order of creation.
guihandles() uses findall(), which returns handles in order according to the Children property of their parent.
The Children property typically has handles in the reverse order of creation. The first entry in Children is the item that is on top, and the last entry in Children is the item that is on bottom. Items created later are typically considered to be on top of items created earlier when those items are at the same depth along the viewing angle (the details depends upon the Renderer; and an additional control became available in R2014b.)
  1 Comment
André
André on 16 Mar 2018
Edited: André on 16 Mar 2018
I know they are stored in FILO, but didn't realise the same would happen with an array created using a single function call. I thought the entire TEXT array would be treated as a single object. So I can use uistack to change the order, but I think I will rather reverse the string array before calling the 'text' function. Anyway, when I updated the handle shouldn't the new order of T4 be kept?
Edit: Problem solved, if I reverse the order using AXES.Children = flipud(AXES.Children), the problem is solved. So I need to change the order directly at the parent handle and not at the handle itself.
Thanks for the answer.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Programming 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!