two consequtive cursor's position in a while loop
Show older comments
Hello,
I have the following proiblem:
I am getting the cursor's poition inside a plot. The code returns only the current position of the cursor. Although I can see the previouse positios but i cant have access to them. What I want is to return the two consequtive position of the cursor (the current poistion and the previous one) inside the while loop.
For example imagine the current position of the cursor is (x1,y1). The next iteration the cursor's position would be (x2,y2). In the current iteration it is (x3,y3). I would like to get (x2,y2) and (x3,y3).
here is what I got so far:
function test_simpleMouseEvents01
SS = get(0,'ScreenSize');
figure('position',[10,10,SS(3)-100,SS(4)-200]); axis off; hold on;
set(gcf,'WindowButtonMotionFcn',{@wbm});
axis([-1,1,-1,1]);
x = [0, 0];
x1 = [];
disp('Move mouse to draw. Press right mouse button to quit.');
while 1
mb = get(gcf,'SelectionType');
if strcmp(mb,'alt')==1
close all;
return;
end
if double(get(gcf,'CurrentCharacter'))==27
close all;
return;
end
cur_point = get(gca,'Currentpoint');
x(1:2) = cur_point(1,1:2)'
assignin('base','x',[x(1,1);x(1,2)]);
plot(x(1), x(2), 'k.','markersize',20);
% x1 = [x1, x']
drawnow;
end
end
%% Mouse move
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function wbm(h,evd)
end
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!