I need ginput help!
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
[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)??
0 Kommentare
Antworten (1)
Image Analyst
am 9 Dez. 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 Kommentare
Image Analyst
am 9 Dez. 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.
Siehe auch
Kategorien
Mehr zu Data Exploration 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!