How do I record responses given with a joystick, instead of the keyboard, in MATLAB?

I would like to record responses given with a joystick, instead of the keyboard, in MATLAB.

 Accepted Answer

Many joysticks are programmable to act like a mouse (i.e., moving the joystick moves the cursor like mouse movements, and clicking a button on the joystick is like clicking the mouse). With one of these joysticks, you can use the MATLAB axis properties in combination with the figure properties to read the position of the cursor moving over a figure window. For example, first plot something in a figure window:
plot(1:10)
Then use the following code which continuously reads the position of the mouse over the figure. You can also specify what to do when a button is clicked.
set(gcf,'WindowButtonMotionFcn','pt=get(gca,''CurrentPoint'')')
It may also be helpful to run and edit the function sigdemo1.m for an example of reading mouse movements. sigdemo1.m is located in $MATLABROOT\toolbox\signal\sigdemo1.m (where $MATLABROOT represents the root directory where MATLAB is installed).

More Answers (0)

Categories

Products

Community Treasure Hunt

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

Start Hunting!