- 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,
How to get the acceleration of the mouse's movement or other user imputs (e.g. trackball)
7 views (last 30 days)
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
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,
Rishabh Singh on 7 Oct 2021
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
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!