我試圖在Matlab中設計和編程一個GUI,但我並不熟悉它。如何在matlab中的數據光標模式打開時獲取點擊點的座標?
基本上,我有兩個組件,它們是「軸」和「列表框」。軸上有一個RGB圖像。我打算將選定的點添加到列表框中。
下面的代碼工作得很好,但我想讓它在數據光標打開時工作。
如何在數據光標打開時使其工作?
% 100x100x3 RGB image
RgbImage = randi(100, 100, 100, 3);
% Draw the image
axesHandle = axes();
imageHande = imagesc(RgbImage);
axis image;
% ButtonDownFc
set(imageHandle, 'ButtonDownFcn', @imageButtonDownFcn);
function imageButtonDownFcn(hObject, eventdata)
p = get(gca, 'CurrentPoint');
x = floor(p(1));
y = floor(p(2));
% Some code to add the [x y] to the list box
end
編輯1: 的問題是,當數據光標在功能imageButtonDownFcn不會被觸發。
從這裏獲取靈感 - http://www.mathworks.in/matlabcentral/fileexchange/38997-ginput-on-gui-keeping-toolbar-features-on-use-of-custom-pointers – Divakar