How can a put a variable into a text string

840 次查看(过去 30 天)
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.

采纳的回答

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 个评论
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 CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by