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

19 Ansichten (letzte 30 Tage)
camile smith
camile smith am 24 Okt. 2016
Beantwortet: Image Analyst am 24 Okt. 2016
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!!!!

Antworten (1)

Image Analyst
Image Analyst am 24 Okt. 2016
Try title()
caption = sprintf('d = %d, p = %d', d, p);
title(caption, 'FontSize', 20);

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by