How can I create a Figure Title with a variable in it?
72 次查看(过去 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 中查找有关 Title 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!