Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 238
Doresoom Avatar asked Aug 18 '10 20:08

Doresoom


People also ask

How do you get a handle of a figure in Matlab?

To get the handle of the current figure without forcing the creation of a figure if one does not exist, query the CurrentFigure property on the root object. fig = get(groot,'CurrentFigure'); MATLAB® returns fig as an empty array if there is no current figure.

How do you do annotations in Matlab?

Create Text Arrow AnnotationCreate a simple line plot and add a text arrow to the figure. Specify the text arrow location in normalized figure coordinates, starting at the point (0.3,0.6) and ending at (0.5,0.5) . Specify the text description by setting the String property.

What is handle visibility in Matlab?

HandleVisibility is a property of all graphics objects. It controls the visibility of the object's handle to three possible values: 'on' — You can obtain the object's handle with functions that return handles, such as ( gcf , gca , gco , get , and findobj ). This is the default behavior.

How do I add annotations in Simulink?

Double-click the canvas where you want to create the annotation and select Create Annotation from the menu. Click the annotation box on the Simulink Editor palette and then click the canvas. Drag the annotation box on the Simulink Editor palette to the canvas. Drag text from another application to the canvas.


1 Answers

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

like image 151
Jonas Avatar answered Nov 15 '22 11:11

Jonas