Here is a modification of some code a kind soul posted on the web. I
would like to collect data while the mouse is down.
What happens is that the program takes the data in only if the mouse
is right on the dot.
I think that is because the even handler that starts the program is
somehow attached to the dot, and not to the whole plot. What do I need
to do to be able to record mouse position as soon as the stylus is
down, regardless of the initial dot position on the screen?
function main
clear all
close all
global data
data=[];
f = figure;
aH = axes('Xlim', [0, 1], 'YLim', [0 1]);
h = plot(0.25, 0.25, '.', 'MarkerSize', 10, 'ButtonDownFcn',
@startDragFcn);
% 'Marke2rEdgeColor' , 'k', ...
% 'MarkerFaceColor' , 'r', ...
% 'MarkerSize', 10, ...
% 'linewidth', 3, ...
% 'ButtonDownFcn', @startDragFcn);
axis([0,1,0,1])
hold on
set(f,'WindowButtonUpFcn', @stopDragFcn);
function startDragFcn(varargin)
set(f, 'WindowButtonMotionFcn', @draggingFcn)
end
function draggingFcn(varargin)
pt = get(aH, 'CurrentPoint');
plot(pt(1,1),pt(1,2),'.');
data=[data;[pt(1,1:2)]];
end
function stopDragFcn(varargin)
set(f, 'WindowButtonMotionFcn', '');
data
end
end
|