필터 지우기
필터 지우기

Getting mouse coordinates with x and y attached to them and displaying them in excel.

조회 수: 2 (최근 30일)
Hello, everybody
A have an issue, I am trying to display the xy coorsdinates of the mouse clicks to an excel sheet. The things is that I am only able to write the numbers but cannot attach x or y to the assigned cell.
here's the code:
[x,y]=ginput(50200)
sheet=1;
xlRange = 'A2';
xlswrite('coordinates.xls',x,sheet,xlRange);
ylRange = 'B2';
xlswrite('cncface.xls',y,sheet,ylRange);
So, my question is, how can i get the coordinates along with 'x' or 'y' attached to them? Displaying the coordinates several times.
Thank you.

채택된 답변

Matt Kindig
Matt Kindig 2013년 3월 25일
Convert x and y to cell arrays with the desired leading text ('x' or 'y'):
xs = [ repmat('x', size(x)), num2str(x)];
ys = [ repmat('y', size(y)), num2str(y)];
Now call xlswrite with xs instead of x, and ys instead of y.
  댓글 수: 5
Walter Roberson
Walter Roberson 2013년 3월 25일
Did you try the cellstr() variation? Another way of coding it would be
xs = cellstr( num2str(x, 'x%.2f') ); %two decimal places
ys = cellstr( num2str(y, 'y%.2f') );
Maria Lopez
Maria Lopez 2013년 3월 25일
Yup, It worked, Thank you, man! I Love You!!!! Have a nice day ahead!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2013년 3월 25일
towrite = {'x'; num2cell(x(:))};
xlrange = 'A1'; %note modification of range
xlswrite('coordinates.xls', towwrite, sheet, xlRange);
towrite = {'y'; num2cell(y(:))};
ylrange = 'B1'; %note modification of range
xlswrite('cncface.xls', towrite, sheet, ylRange);
Is it correct that you are wanting to write them to different files?
  댓글 수: 1
Maria Lopez
Maria Lopez 2013년 3월 25일
Didnt work, It only writes x and y to A1 and B1. The coordinates ar not shown, but thank you. (Typo, they both go to the same file: cncface.xls)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by