Stubborn annotation? Cannot be found by a search? Even though it exists...
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I'm using a 'line' annotation to show a selected pixel color in my script. I programmatically create the annotation using this code :
SampledColor = annotation(FigureH, 'line', 'Units', 'Pixels','Tag','LineRB', 'Position', [70 50 Width 0], 'Color','k','LineWidth',10);
hSampledColor = findobj('Tag','LineRB');
Trouble is, the 'tag' property does not seem to be recognized or registered? The first line above executes fine but the following line, findobj('Tag', 'LineRB') only returns an empty 0x0 matlab.graphics.GraphicsPlaceholder?
To work around the problem, I found I could first 'zap' the area where the line is drawn in the figure using this statement :
WhiteLine = annotation(FigureH, 'line', 'Units', 'Pixels','Tag','LigneRB', 'Position', [0 50 FigureWidth 0], 'Color','w','LineWidth',10);
It works but I'd love to be able to tell whether the annotation exists before creating it, so that I could delete it using these statements:
hLigne = findobj('Tag','LineRB');
if ~isempty(hLigne)
delete(hLigne);
end
0 Commenti
Risposte (1)
Voss
il 17 Feb 2022
The reason findobj() doesn't work is because SampledColor's parent AnnotationPane has its 'HandleVisibility' set to 'off':
FigureH = gcf();
Width = 100;
SampledColor = annotation(FigureH, 'line', 'Units', 'Pixels','Tag','LineRB', 'Position', [70 50 Width 0], 'Color','k','LineWidth',10);
get(get(SampledColor,'Parent'))
hSampledColor = findobj('Tag','LineRB')
To find objects with 'HandleVisibility' set to 'off' (or their descendants in this case), you can use findall() rather than findobj():
hSampledColor = findall(FigureH,'Tag','LineRB')
Note that findall() requires a handle (or array of handles), e.g., a figure, as its first argument, whereas this is optional in findobj().
0 Commenti
Vedere anche
Categorie
Scopri di più su Specifying Target for Graphics Output in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!