I need ginput help!

4 visualizaciones (últimos 30 días)
Arisa.S
Arisa.S el 9 de Dic. de 2015
Comentada: Image Analyst el 9 de Dic. de 2015
[x_click, y_click] = ginput(1);
x = floor(x_click);
y = floor(y_click);
[x y] = ginput(1); %input from letters
[p q] = ginput(1); %click on a box
The above is the code for a ginput for a scrabble board being made via plot command. How do I set the code for ginput of x and y such that when I click on point (p,q) on the board, the letter that I clicked on (the one set at (x,y)) will be displayed at (p,q)??

Respuestas (1)

Image Analyst
Image Analyst el 9 de Dic. de 2015
I don't see why you need three ginputs instead of just 1.
You need to compare (x_click, y_click) to the locations (xLetters, yLetters) of all the letters and figure out which is closest.
uiwait(msgbox('Click on a letter'));
[x_click, y_click] = ginput(1);
distances = sqrt((x_click - xLetters).^2+(y_click-yLetters).^2);
[~, indexOfClosest] = min(distances);
% Get the letter from the cell array of letters (or you can use a character array).
chosenLetter = listOfLetters{indexOfClosest);
% Place the letter on the image there.
text(xLetters(indexOfClosest), yLetters(indexOfClosest), chosenLetter);
Then use text() to display a letter.
  2 comentarios
Arisa.S
Arisa.S el 9 de Dic. de 2015
How should I set xLetters and yLetters then?
Image Analyst
Image Analyst el 9 de Dic. de 2015
You said "the letter that I clicked on (the one set at (x,y))" so I assumed you had a list of letter locations that you used in advance to build the board. Do you not know what letters are in what locations? If not, then how did you build the board? Is the board an image? Please post pictures, images, or screenshots to illustrate your situation. Otherwise I don't know and I'm just guessing.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Exploration 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