How can a put a variable into a text string

811 ビュー (過去 30 日間)
Mitchell Frechette
Mitchell Frechette 2016 年 10 月 28 日
コメント済み: Steven Lord 2022 年 3 月 14 日
I want to put a variable onto a graph.
I have tried text(x,y,'Text ' num2str(variable) ' moretext') with no luck.
The only information I can find is how to put a variable in the title of a graph. I simply want it to be displayed at a location of my choosing on the graph.
  1 件のコメント
Antonia Ciocoiu
Antonia Ciocoiu 2018 年 7 月 6 日
編集済み: Antonia Ciocoiu 2018 年 7 月 6 日
a=(['Testing',num2str(2)]);
plot(x,y) %% plot your variables
xlabel(a)

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

採用された回答

Star Strider
Star Strider 2016 年 10 月 28 日
Use the sprintf function:
text(x, y, sprintf('Text %f more text', variable))
NOTE This is UNTESTED CODE but it should work. Change the format descriptor in sprintf as necessary to provide the result you want.
  2 件のコメント
Diana Tsvetkova
Diana Tsvetkova 2022 年 3 月 14 日
it works, and it helped me a lot. Thanks !
Steven Lord
Steven Lord 2022 年 3 月 14 日
If you're using a recent release (one that supports string arrays) you can use that.
text(0.5, 0.5, "Text " + pi + " more text")

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by