How can I add text to a plot?

45 ビュー (過去 30 日間)
Lukas
Lukas 2014 年 2 月 4 日
コメント済み: DONA MERIN JOY 2017 年 3 月 21 日
I want to add some text to my graph. I have been through lots of documentation of the text() command. For some reason it just doesn't want to work. I know that sounds like I haven't tried fixing it myself but I have and I'm at a complete loss.
I have tried running the exact example code in the documentation and I receive one of two errors.
??? Subscript indices must either be real positive integers or logicals.
Error in ==> Untitled2 at 2
text(pi,0,' \leftarrow sin(\pi)','FontSize',18)
Or if I make them positive and real integers
??? Index exceeds matrix dimensions.
Error in ==> Untitled2 at 2
text(1,1,' \leftarrow sin(\pi)','FontSize',18)
The example code that I tried running on my PC from the documentation:
plot(0:pi/20:2*pi,sin(0:pi/20:2*pi))
text(pi,0,' \leftarrow sin(\pi)','FontSize',18)
Here is a link to the documentation with the correct output.
Thanks
  1 件のコメント
Mischa Kim
Mischa Kim 2014 年 2 月 4 日
Lukas, is the error really referring to the text command? How does the rest of the code look like?
What MATLAB version are you using on what platform?

サインインしてコメントする。

採用された回答

Robert Cumming
Robert Cumming 2014 年 2 月 4 日
Is text a variable in your workspace?
Type:
whos text
In the command line to check.
clear text
To clear the variable -> then try the example from the documentation again.

その他の回答 (2 件)

David Sanchez
David Sanchez 2014 年 2 月 4 日
The error message you pasted refers to a *.m file called Untitled2.m.
Do the following and tell us what you get:
On the command window:
clear all
plot(0:10,0:10)
text(5,5,'TEST TEXT')
Your error message has nothing to do with the text command.
  2 件のコメント
Anand
Anand 2014 年 4 月 25 日
Hi, I have managed to read and display text within a running AVI video file, but now i want to only add text to certain frames...e.g frame 1-20 and 30-40....is there any way i can i can add text from one frame to another instead of it displaying throughout the whole video.
thank you.
Title_={'Smile'};
hText = text(x,y,'string');
imshow(Background);
text(40,100,Title_{1},'Color','r','FontWeight','Bold','FontSize',40);
delete(htext);
DONA MERIN   JOY
DONA MERIN JOY 2017 年 3 月 21 日
how can i display a word in figure window in matlab

サインインしてコメントする。


Lukas
Lukas 2014 年 2 月 4 日
Ah thanks Robert. Yes I must have created a variable somewhere called text. I'm sure the clear all command would have worked as well thanks David. I will always use it from now on.
Thanks everyone.
  1 件のコメント
Robert Cumming
Robert Cumming 2014 年 2 月 4 日
See this LINK on why using clear all is not always a good idea...

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by