How do I display variable values on my figure window???
5 views (last 30 days)
Show older comments
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!!!!
0 Comments
Answers (1)
Image Analyst
on 24 Oct 2016
Try title()
caption = sprintf('d = %d, p = %d', d, p);
title(caption, 'FontSize', 20);
0 Comments
See Also
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!