How to read and write .nex and .nex5 files in Matlab, Python, C++ and C#

.nex and .nex5 files are binary files with the following general structure:

  • File header (number of variables in file (N), etc.)

  • Variable1 header (variable name, number of values, etc.)

  • Variable2 header (variable name, number of values, etc.)

  • VariableN header (variable name, number of values, etc.)

  • Variable1 data (timestamps, continuous values, etc.)

  • Variable2 data (timestamps, continuous values, etc.)

  • VariableN data (timestamps, continuous values, etc.)

The code to read and write .nex and .nex5 files is available in the following zip files:

File Name

Description

HowToReadAndWriteNexAndNex5FilesInMatlab.zip

Matlab code to read and write .nex and .nex5 files

HowToReadAndWriteNexAndNex5FilesInPython.zip

Old Python code to read and write .nex and .nex5 files. See also nex5file Python package documentation

HowToReadAndWriteNexFiles.zip

C++ code to read and write .nex files

HowToReadAndWriteNex5Files.zip

C++ code to read and write .nex5 files

NeuroExplorerNexFileCSharp.zip

C# code to read and write .nex and .nex5 files

README.txt file in each of these zip files contains instructions on how to use the code.