How to create a textbox using annotation, that includes matlab shapes?

Hi,
I am trying to include a textbox in an image, to describe some of my symbols. To do this, I am using the matlab function "annotation", with the string
str={'X','Y','Z'};
What I would like is that, in the textbox, before the X there is a blue square as the usual 's' in Matlab. Similary with a red diamond 'd' for Y, and a green circle for Z.
Is this doable?
Thanks!

 Accepted Answer

While apparently theoretically possible to mung on the vertices of an annotation object to change the shape --
figure
hF=gcf;
p=hF.Position; p(3)=p(4); hF.Position=p; % make it square aspect ratio
hASq = annotation('rectangle','FaceColor','b','linestyle','none'); % put a square on it, get handle
hFace=hASq.Face; % the hidden quadrilateral object
v=single(zeros(3,4)); % generate set of vertices within the default position
v(1:2,1)=[0.35;0.3];
v(1:2,2)=[0.3;0.35];
v(1:2,3)=[0.4;0.35];
v(1:2,4)=[0.35;0.4]
hFace.VertexData=v; % set the vertices to new data
generates an initial figure that looks like
any time the figure is repainted, the image reverts back to the original square -- there's a lot more behind the scenes than just simply resetting the vertices, unfortunately.
Secondly from a practical standpoint for your purposes, an annotation object and textbox can't be mixed, you would have to draw each separtely and position them such that they appeared to be together.
All in all, methinks this would not be fruitful path to try to follow; not sure there is a good path...

6 Comments

I changed my approach in the end. Instead of using colored shapes, I searched for non-colored symbols that appeared both in latex and in Matlab, and used latex within the annotation.
Thanks anyway! It was helpful to know that there might be not good path.
I wonder if emojis would be useful. (more info)
hold on
text(.2, .5, char([9829 65039]),...
'fontsize', 18, ...
'HorizontalAlignment','Center',...
'VerticalAlignment','middle')
text(.8, .5, char([9830 65039]),...
'fontsize', 18, ...
'HorizontalAlignment','Center',...
'VerticalAlignment','middle')
I am not familiar with them. Are you defining the emojis with the char([9829 65039])? Is it possible to change their colors?
They're whatever is the code for the current active character set -- and, yes, all the properties of a text object are in play...
I suggest you experiment with it to answer these questions. The emojis may not appear exactly how they normally would in text. For example, filled emojis may only appear as edges and the edge color is settable using text(___,'color',__). See the "more info" link I provided above.

Sign in to comment.

More Answers (0)

Categories

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!