Determine if mouse click on a plot is within plot region
3 次查看(过去 30 天)
显示 更早的评论
采纳的回答
更多回答(2 个)
Matt Fig
2011-4-5
Here is a way to do it programmatically, as in a GUI for example. Save this in an M-file then run the M-file. Click on the axes or outside the axes:
function [] = example()
fh = figure;
axes('units','pix')
plot(1:10)
set(fh,'windowbuttondownfcn',{@fhbdfcn,get(gca,'position')})
function [] = fhbdfcn(varargin)
% WindowButtonDownFcn for figure.
P = varargin{3};
cp = get(varargin{1},'currentpoint');
if cp(1)>P(1) && cp(2)>P(2) && cp(1) < (P(1)+P(3)) && cp(2)<(P(2)+P(4))
disp('In Axes')
else
disp('Not in Axes')
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Exploration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!