text object array being reversed when retrieved from handle
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Jan
il 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"?
Risposta accettata
Walter Roberson
il 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.)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Graphics Object Programming in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!