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

18 visualizaciones (últimos 30 días)
camile smith
camile smith el 24 de Oct. de 2016
Respondida: Image Analyst el 24 de Oct. de 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!!!!

Respuestas (1)

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

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by