How can I create a Figure Title with a variable in it?

조회 수: 91 (최근 30일)
onamaewa
onamaewa 2019년 5월 28일
편집: Stephen23 2019년 5월 29일
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?

답변 (1개)

Adam Danz
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 CenterFile Exchange에서 Labels and Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by