MEX code for using SDL joysticks and game controllers in MATLAB.

If you’re looking to use joysticks or game controllers in MATLAB, you can use the MEX files in matlab-sdl-joystick to get access to all axes and buttons. If you need to build the MEX files yourself, then you need to compile both C++ files using mex in MATLAB. SDL2 is a depedency, so make sure to install it first on your platform. Then, use these two commands build the MEX files:

>> mex Joystick.cpp -lSDL2
>> mex GameController.cpp -lSDL2

The MEX files need to be compiled only once. To access the axes and button data of the first available joystick, use the following code snippet:

[axes, btns] = Joystick();

All source code can be found in this Git repository.

Except where otherwise noted, the contents of this post are licensed under Creative Commons Attribution 4.0.

Creative Commons License