开发者

How do I find an annotation handle in MATLAB?

I'm trying to implement a modified version of datetick2 from the MATLAB FEX. When plots are zoomed in on a small date range, the day/month/year, etc. isn't shown, depending on the range of times in the plot. I'd like to put a 'dd-mmm-yyyy' formatted starting date as an annotation in the bottom left corner of the figure. No problem, that's done.

However, next I want to have it update if the user selects a different date range with the zoom function. Instead of passing more handles, I want to just find the annotation. However, findobj doesn't seem to work for the hggroup type, which is what annotations fall under. Am I using it wrong?

Here's a code example:

>> times=now-[50:-5:0];
>> days=times-times(1);
>> plot(times,days)
>> datetick2()
>> xlabel('Date')
>> ylabel('Days')
>> title('Example')
>> initialdate=datestr(min(get(gca,'xlim')),'dd-mmm-yyyy');
>> txt=annotation('textbox', [.01,.01,.1,.05],...
                  'string',  initi开发者_运维问答aldate,...
                  'Linestyle','none');
>> 
>> 
>> findobj('type','hggroup')

ans =

   Empty matrix: 0-by-1

>> get(txt,'type')

ans =

hggroup

>> findobj('type','axes')

ans =

  270.0034

As you can see, findobj doesn't work, but if I use the handle I defined in the workspace, the type pops right out as hggroup.


Instead of findobj, I use FINDALL, since it allows me to keep hidden handles hidden. findall needs a handle starting from which it recursively searches the children. findall(0,'Tag','myTag') finds all objects taggedmyTag(0 is the handle to root),findall(gcf,'Tag','myTag') finds the objects tagged myTag that are associated with the current figure (including the figure itself, in case it has the right tag).


You may have to first set the root 'ShowHiddenHandles' property to 'on', then try using FINDOBJ to find your object, then set it back to the default 'off'.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜