I need ginput help!
조회 수: 3 (최근 30일)
이전 댓글 표시
[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
답변 (1개)
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
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 Center 및 File Exchange에서 Data Exploration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!