draw polygon continuously with mouse
4 ビュー (過去 30 日間)
古いコメントを表示
לק"י
Hi guys,
I need to contour some cells. I want to use the drawpolygon command, or an equivalent of it, that will record mouse position continuously while mouse left click button is held. No such option seems to be in the drawpolygon documentation.
There are some old answers about how to do it, the problem is that most of the codes there somewhy don't work when I try to use them. Is there any other easy/quick way to obtain mouse position only when left mouse button is held?
Thanks,
Amit.
0 件のコメント
回答 (1 件)
Piyush Kumar
2024 年 7 月 30 日
編集済み: Piyush Kumar
2024 年 7 月 30 日
You can use "WindowButtonMotionFcn". Read more about this from "Window Callbacks" section of this documentation link.
Step 1: Create a file named "drawPolygon.m" with the following content -
function drawPolygon()
figure('WindowButtonMotionFcn', @mouseMove);
global isDown;
isDown = false;
set(gcf, 'WindowButtonDownFcn', @mouseDown);
set(gcf, 'WindowButtonUpFcn', @mouseUp);
end
function mouseMove(src, event)
global isDown;
if isDown
C = get(gca, 'CurrentPoint');
disp(['Cursor position is (' num2str(C(1,1)) ', ' num2str(C(1,2)) ')']);
end
end
function mouseDown(src, event)
global isDown;
isDown = true;
end
function mouseUp(src, event)
global isDown;
isDown = false;
end
Step 2: From MATLAB command line, run the file -
drawPolygon
Step 3: In the figure, you keep moving the cursor and you will get the current position of the cursor live in the MATLAB command line.
Let me know if this helps!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Contour Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!