How can I create a Figure Title with a variable in it?
84 ビュー (過去 30 日間)
古いコメントを表示
I have a figure:
DEPTH = 10; % Depth changes based on user input
figure('Numbers at a depth of %d meters)')
How can I make my figure title update depending on my input for depth?
0 件のコメント
回答 (1 件)
Adam Danz
2019 年 5 月 28 日
編集済み: Adam Danz
2019 年 5 月 29 日
DEPTH = 10; % Depth changes based on user input
title(sprintf('Numbers at a depth of %.0f meters', DEPTH))
% For the figure name (not title):
figure('Name', sprintf('Numbers at a depth of %.0f meters', DEPTH))
I prefer %.0f rather than %d to convert integers because 1) if DEPTH isn't an integer, %d will print out scientific notation and 2) if you ever want to add decimal places you can just change the 0.
参考
カテゴリ
Help Center および File Exchange で Labels and Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!