views:

45

answers:

2

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',  initialdate,...
                  '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.

+3  A: 

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'.

gnovice
Yup, that was it. I added a tag property to the annotation as well, just to make things even easier.
Doresoom
+5  A: 

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).

Jonas
+1: I don't think I've ever heard of FINDALL!
gnovice
+1 That's a new one for me too.
Doresoom

related questions