To obtain the properties and values of annotation objects in the current figure, search the figure using the FINDALL function to locate hggroup objects that are children of the annotation object parent axes. The following code provides an example:
close all
clear all
annotation('textbox',[0.5 0.5 0.1 0.1],'string','hello world');
annotation('textbox',[0.7 0.9 0.1 0.1],'string','hello world1');
annotation('textbox',[0.2 0.2 0.1 0.1],'string','hello world2');
annotation('line',[0.2 0.2],[0.8 0.3]);
fig = gcf;
ax = findall(fig, 'Type', 'axes', 'Tag', 'scribeOverlay');
annotation_handles = findall(get(ax,'Children'),'Type','hggroup');
ss = size(annotation_handles);
j = max(ss);
for i = 1:j
hh = get(annotation_handles(i));
if(isfield(hh,'String'))
text_string{i} = get(annotation_handles(i),'string');
else i = i+1;
end
end
text_string
It is important to note that all annotation objects are of type 'hggroup' and hence based on the type you cannot determine whether it is a textbox or a line. Hence, you will need to find if the 'String' property exists in the handle structure of the annotation object.
Best Answer