output matlab markers as part of a character string.

16 views (last 30 days)
It's amazing that nobody has asked this before, but I'd like to insert the standard matlab plot markers---square, diamond, circle, etc---into a character string. Presumably this is possible?
For reasons too banal to explain, it's not easy for me to use the standard legend commands, and the quickest quick-dirty fix is to create my own, as annotations.
Thanks for any suggestions how to do this.
PS, I'm getting closer to doing this with unicode characters. Could anybody please tell me the matlab unicode character for an unfilled diamond? I've found circle (9711) and square (9744).
Thanks very much!

Accepted Answer

Cindy Solomon
Cindy Solomon on 28 Jul 2015
Hi Leo,
To add to Walter's comment, (if I understand what you are trying to do correctly), I would also recommend looking into the native2unicode function or the reverse (unicode2native). These combined with the char function can let you insert a variety of characters in as plot markers. For example:
%*** Create A Plot With NO Markers ***
x = 1:40;
y = rand( 1, 40 );
plot( x, y );
axis( [0.5, 40.5, -0.1, 1.1 ] );
%*** Add Filled Markers from 1 to 10 (u+2776 to u+277F) ***
for i = 1:10
nativeValue = char( hex2dec( '2776' ) + i - 1); %Native format (bit/byte arrangement)
unicodeValue = native2unicode( nativeValue, 'UTF-16' ); %Convert to Unicode 16 format
text( x( i + 20 ), y ( i + 20 ),... %Position of font character
unicodeValue,...
'FontSize',12,... %Set font size to 12
'HorizontalAlignment', 'Center',... %Center character on point
'VerticalAlignment', 'Middle' );
end
I apologize if I misunderstood your question, but hope this is helpful!
  1 Comment
Leo Simon
Leo Simon on 29 Jul 2015
This is really great, thanks very much indeed. I have remaining two questions. First, how can I get the numbered balls to show up in a legend? The legend command thinks that stem is the only thing it has to report. Second, in the code below, I've modified your code to use stem. As you will see, I reduced the height of the y vector so that the top of the line didn't protrude into the blue circle. But I poorly eyeballed the value of offset in the code. If I could get the radius of the ball in figure coordinates. then I could use axxy2fixxy to get the length of the line exactly.
close all
x = 1:10;
y = rand( 1, 10 );
axis( [0.5, 10.5, -0.1, 1.1 ] );
offset = 0.06;
numInBall = @(i)native2unicode( char( hex2dec( '2776' )+i-1), 'UTF-16' );
hold on;
for i = 1:10
hT = text( x( i ), y ( i ), numInBall(i),...
'FontSize',20, 'Color','b', 'HorizontalAlignment', 'Center', 'VerticalAlignment', 'Middle' );
end
hS = stem( x, (y - offset) ,'Color','b','Marker','none');

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!