Hi I'm really new to MATLAB and I'm generating images which are a set of 9 letters encased in a rectangle. I can do this with symbols (such as +) but I need to use letters in place of the symbols.
How do I replace the symbols with normal letters?
Thanks

 채택된 답변

Star Strider
Star Strider 2014년 10월 17일

1 개 추천

You have to use the text function to label your points with letters.
Example:
x = randi(10, 1, 5); % Create Data
y = randi(10, 1, 5);
L = strsplit(sprintf('%c\n','A':'E')); % Letter Labels
figure(1)
plot(x, y, '+r')
text(x, y, L(1:length(x)), 'HorizontalAlignment','center', 'VerticalAlignment','bottom')
axis([-0.5 10.5 -0.5 10.5 ])

댓글 수: 4

Alice
Alice 2014년 10월 20일
Thank you!
Alice
Alice 2014년 10월 20일
Is there any way that you can plot just the letters, so they are not labels, but instead of '+' you use 'A'?
My pleasure!
Just change the plot call to:
plot(x, y)
In that situation, you may also want to change the text call to:
text(x, y, L(1:length(x)), 'HorizontalAlignment','center', 'VerticalAlignment','center')
to plot the letters exactly on top of your data points.
Update:
In recent version, replace 'center' by 'middle' only in 'VerticalAlignment' value in text call.
text(x, y, L(1:length(x)), 'HorizontalAlignment','center', 'VerticalAlignment','middle')

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Robert Cumming
Robert Cumming 2014년 10월 17일

0 개 추천

The text function allows you to write text on an axes.
help text

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

태그

질문:

2014년 10월 17일

댓글:

2019년 6월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by