I have a gui that includes a plot. In this plot I add an annotation. When the plot data is changed using the gui, he old annotation remains and the new one is plotted over the old on.
So I need to remove he old annotation.
I tried the following code, but that has no effect:
set(0,'showhiddenhandles','on')
% look for all axes in the figure of choice:
h_all_axes = findall(gcf,'type','axes');
% get the 'annotation layer' axes handle:
h_anno_axes = double(find(handle(h_all_axes),'-class','graph2d.annotationlayer'));
delete(h_anno_axes);
set(0,'showhiddenhandles','off');
annotationPos = [0.55 0.58 0.6 0.3];
htxtbox = annotation('textbox',annotationPos, ...
'String' ,strtextbox, ...
'FontSize' ,FontSize+1, ...
'FitBoxToText', 'on', ...
'EdgeColor', 'none', ...
'FontName' , 'Courier New');
The easiest solution is to add a specific tag to the annotation.