I need ginput help!

4 次查看(过去 30 天)
Arisa.S
Arisa.S 2015-12-9
[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)??

回答(1 个)

Image Analyst
Image Analyst 2015-12-9
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 个评论
Arisa.S
Arisa.S 2015-12-9
How should I set xLetters and yLetters then?
Image Analyst
Image Analyst 2015-12-9
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Exploration 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by