How can a put a variable into a text string
811 ビュー (過去 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.
1 件のコメント
Antonia Ciocoiu
2018 年 7 月 6 日
編集済み: Antonia Ciocoiu
2018 年 7 月 6 日
a=(['Testing',num2str(2)]);
plot(x,y) %% plot your variables
xlabel(a)
採用された回答
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
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 Exchange で Characters and Strings についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
