MATLAB Answers

How to get the acceleration of the mouse's movement or other user imputs (e.g. trackball)

5 ビュー (過去 30 日間)
francesco turco
francesco turco 2021 年 10 月 3 日
コメント済み: francesco turco 2021 年 10 月 8 日
I am working on a alertness task to detect brief lapses of vigilance. Briefly, an object is continuosly moving away from the centre of the screen (or figure), while the user is asked to continuosly keep it back to the centre of the screen. The creators of the task provided an equation of the motion that gives the position of the object in each time frame when two centrifugal forces and the user imput force are known.
I am triyng to code the user imput force, and I managed to get it from the position of the mouse for each time frame (each cycle loop), as described below:
dt = 0.1; % time step for animation
t = 0:dt:20 ; % time length of the animation
A=ones(length(t),2); % A=accelaration
for i=2:length(t)
C(i,:)=get(0, 'PointerLocation');
for ii=2:length(t)
I doubt this is the best solution:
1) it ceases to work when the mouse reach the border of the screen, and the user must move it back
2) I wonder if there will be problems of time-accuracy
Thank you very much for helping me!
All the best,
  1 件のコメント
francesco turco
francesco turco 2021 年 10 月 3 日
The wider question (maybe of interest also for other matlab users) would be "Is it possible to get the movement/postion of the mouse outside the screen borders?"


回答 (1 件)

Rishabh Singh
Rishabh Singh 2021 年 10 月 7 日
According to my understanding, you wish to calculate the acceleration of the mouse pointer.
Possible way around for this would be using a 3-point instead of 2.
For acceleration calculation, and , .
So firstly, calculate the velocity and then acceleration.
To improve the accuracy of your calculation, consider
  • decreasing value of ‘dt’ variable.
  • Avoid any print or display statement in the ‘for’ loop, as they increase execution time.
  • Use tic-toc to calculate time to execute the for loop. For example,
for i=2:length(t)
t_actual = toc;
time_gap(i+1) = t_actual;
pointer_location(i,:) =get(0, 'PointerLocation');
Can you elaborate what you mean my location of pointer outside the screen?. According to me, the cursor/pointer it bound to stay within the screen, and as “get(0, ‘PointerLocation’)” gives pointer location as in pixel coordinates, so it’s not possible to get location outside the screen.
Hope this helps!
  2 件のコメント
francesco turco
francesco turco 2021 年 10 月 8 日
E.G. The dot is moving rightward, the user moves the mouse leftward to keep the dot close to the center of the screen. When the mouse pointer reaches the bound of the screen, the user movement leftward ceases to be effective.


Community Treasure Hunt

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

Start Hunting!

Translated by