How do I display variable values on my figure window???

This is my code so far. It basically changes the location of an image based on how many times I press the arrow key. All I want to do is display the variable values d and p in the figure window that pops up.
d = 20
p = 20
f = figure;
k=1;
while k
waitforbuttonpress;
if get(gcf,'CurrentCharacter')==28 %left arrow key
d=d-10
elseif get(gcf,'CurrentCharacter')==29 %right arrow key
d=d+10
elseif get(gcf,'CurrentCharacter')==31 %down arrow key
p=p-10
elseif get(gcf,'CurrentCharacter')==30 %up arrow key
p=p+10
elseif get(gcf,'CurrentCharacter')==32 %space bar
break
end
cla reset
axis([-400,400,-200,200]);
hold on
ax = gca;
ax.XTick = [];
ax.YTick = [];
ax.DataAspectRatioMode = 'manual';
ax.DataAspectRatio = [1 1 1];
ax.PlotBoxAspectRatioMode = 'manual';
ax.PlotBoxAspectRatio = [1 1 1];
img = imread('eyechart1.jpg');
image([d -p],[d -p],img);
end
I would like to display the d and p variable values on the figure window. What syntax would I use for this? Thanks!!!!

回答(1 个)

Try title()
caption = sprintf('d = %d, p = %d', d, p);
title(caption, 'FontSize', 20);

类别

帮助中心File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by