[英]How do I write coordinates to a text file after a mouse click? [MATLAB]
目標 :在Matlab GUIDE中單擊鼠標(使用“數據光標”工具)后,將(x,y)坐標寫入文本文件(.txt)。
我試圖弄清楚如何在選擇了數據游標工具的情況下單擊鼠標,然后將坐標輸出到文本文件,格式如下所示。 我希望能夠無限制地單擊鼠標按鈕,並將所有這些坐標寫入文件。
寫入文件格式 :
點號x,y
步驟 :
單擊“數字化”時 :
function digitize_Callback(hObject, eventdata, handles)
datacursormode on
!notepad.exe &
使用dcm_obj = datacursormode();
和info_struct = getCursorInfo(dcm_obj);
。 例如,您可以像這樣在循環中使用它們:
x = 0:0.1:1;
plot(x, x.^2, 'ro');
dcm_obj = datacursormode();
info_struct = [];
while true
info_struct = getCursorInfo(dcm_obj);
if ~isempty(info_struct)
fprintf('you chose point no. %d\n',info_struct.DataIndex);
fprintf('with coordinates: [x:%1.2f, y:%1.2f]\n\n',info_struct.Position(1),info_struct.Position(2));
break
end
pause(0.05)
end
您將獲得:
you chose point no. 9
with coordinates: [x:0.80, y:0.64]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.