MATLAB Answers

How can I constrain ginput to not respond if clicked outside the axes?

14 ビュー (過去 30 日間)
Ranjan Sonalkar
Ranjan Sonalkar 2020 年 10 月 15 日
編集済み: Ranjan Sonalkar 2021 年 3 月 12 日
I am using ginput to pick points within a 2D scale with a range +-1 in both axes. I have some action buttons outside the scale. The documentation for ginput says that if the mouse button is clicked even when the cursor is outside the scale, it will pick that point relative to the origin of the scale. Of course, I can ignore any points outside the range using a while loop, for example. But, if the user inadvertantly presses the mouse button while the cursor is on an action button outside the scale, it activates the action. I would like to prevent the user from doing this, i.e. essentially deactivate/ignore the ginput selection if the cursor is outside my intended axes..
Any idea how I can do this?

回答 (2 件)

Shraddha Jain
Shraddha Jain 2021 年 3 月 10 日
Hi Ranjan,
There is no functionality of setting custom axes boundary coordinates in the ginput function as of now, it might be considered in a future release.
As a possible workaround, you may add a function in your code which filters out the coordinate points that are outside the area of intended axes.
  1 件のコメント
Ranjan Sonalkar
Ranjan Sonalkar 2021 年 3 月 12 日
The next anwser to disable buttons works better. My main problem is not that ginput will select points outside the valid region, but that it will inadvertantly push an action button.

サインインしてコメントする。


Walter Roberson
Walter Roberson 2021 年 3 月 10 日
For the duration of the ginput() call, disable the action buttons by setting their 'enable' property to 'inactive'. Or set their visibility to off.
This is certainly not as nice as an ability to confine a ginput() to a certain axes would be, but it is something .
currently_on = findall(gcf, 'type', 'uicontrol', 'Enable', 'on');
cleanme = onCleanup(@() set(currently_on, 'Enable', 'on'));
set(currently_on, 'Enable', 'inactive');
[X,Y] = ginput(N);
clear cleanme %restore them

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by