This is the MATLAB interface for liblsl.
First try getting the latest release for your platform and Matlab version from the release page. Unfortunately, Matlab is very strict about using the exact right versions of binaries, and there is no easy way to automate Matlab releases (see #17), so it is very much a matter of luck as to whether or not we happen to have a release that will work for you.
Instead, you can download the source, the dependencies, and build yourself. This may sound intimidating but we've tried to automate some of the work for you. If you're lucky then it might be easier than you think.
- Clone or download a zip of this repository from https://github.com/labstreaminglayer/liblsl-Matlab
- If you downloaded the zip, extract it somewhere convenient.
- Ensure you have an up-to-date build of the liblsl library binary available.
- Option 1: Do nothing and it will download automatically when first required.
- This might fail, or even if it succeeds in downloading the file, you might still get errors trying to load the library. Try Option 2 next.
- Option 2: Download precompiled libraries from the liblsl release page and place it in the
liblsl-Matlab/bin
folder.- See here for more information about which library you need.
- This doesn't always work, unfortunately. Try option 3.
- Option 3: Build it yourself.
- See here for instructions.
- Option 1: Do nothing and it will download automatically when first required.
- Build the mex files.
- In Matlab: Change Matlab's working directory to this repository's root (i.e., liblsl-Matlab) and run
build_mex
. - From the command line:
matlab -nodesktop -nosplash -r 'build_mex'
- You may need to install a compiler. See here for supported compilers. For Windows users, this usually means installing Visual Studio.
- In Matlab: Change Matlab's working directory to this repository's root (i.e., liblsl-Matlab) and run
- Add the liblsl-Matlab folder to your MATLAB path recursively
- Using the MATLAB GUI, use File/Set Path...
- Alternatively, in a script, use
addpath(genpath('path/to/liblsl-Matlab'));
- Load the library then call a function.
lib = lsl_loadlib(); version = lsl_library_version(lib)
- See the example files in the examples/ directory for more examples of how to use this interface in a MATLAB program.
If you get an error similar to lsl_loadlib_ undefined
, then try following the "From Source" directions above.
On MacOS, you may still get an error similar to Invalid MEX-file [...] lsl_loadlib_.mexmaci64; Reason: image not found.
. To fix this run the following command in a Terminal window from within the liblsl-Matlab directory: install_name_tool -add_rpath "@loader_path/" bin/lsl_loadlib_.mexmaci64
If you still can't get it to work then open an issue here and hopefully someone who has the same platform and Matlab version as you can build and upload a release for you.