Reading matrices from MATLAB (.mat) in C#

Since last year, it is now possible to read MATLAB files from .NET applications using the Accord.NET Framework. Let’s say you have a .mat file stored in your desktop. You can load it in C# using:

To install the Accord.NET Framework into your C# application, install Accord.Math and Accord.IO through NuGet.


  1. Cesar – is amazing – I’m only beginning to scratch the surface of it’s functionality. Thank you.

    I very much enjoy using your samples, but am concerned/confused with applying them into a production environment.

    Documentation or a tutorial would be quite helpful on migrating from “training” to production (where memory is at a premium, so hopefully only the weights/bias/etc is used, not the entire dataset in a training model scenario). Most ML models require “training data.” When the sample program is stopped, the training is gone. I saw you had a post regarding Accord.IO to serialize objects. When this occurs, does the entire learned data stay in memory, or are only the critical variables (weights, etc) instantiated?

    In a production environment, it would be nice if there were “lightweight” versions of the models (perhaps memory and processor optimized) that drove decisions after being trained in a development environment – lightweight models that could continue to learn, where reinforced data could be saved in the event a server needs to be upgraded/rebooted, etc. Are there any “production roadmaps” that you or others have written?

    Thank you again for your efforts in creating an amazing library.


  2. Thanks for amazing work.

    Actually I have a Issue with this framework, I try to run in other software(No Visual Studio), but fire a issue when this program start.

    The issue shows this:

    26/12/2017 8:10:22 p. m. Default Unable to retrieve type infos from assembly ‘Accord.Math’: System.Reflection.ReflectionTypeLoadException: No se pueden cargar uno o varios tipos requeridos. Recupere la propiedad LoaderExceptions para obtener más información.
    en System.Reflection.Module._GetTypesInternal(StackCrawlMark& stackMark)
    en System.Reflection.Assembly.GetTypes()
    en NinjaTrader.Cbi.AssemblyDictionary.GetTypes(Type superClass)

    I have no idea why, every assembly load correctly except ‘Accord.Math’. the DLL´s imported are Accord.dll

    Thanks for any help!

  3. Dear Cesar,
    Are you aware of any Accord source code, preferably VB.NET, for EEG or MRI data? They are usually in Matlab MAT files by the way. I will be happy to collaborate.

  4. Using third party huge library to just read data is extremely inefficient and unprofessional, considering you have software that should fit in 50 mb or less and have one codebase that runs on multiple platforms. Why not have one class that does all what you need instead of 500+ mb of unused code in huge accord library . . .

Leave a Reply

Your email address will not be published. Required fields are marked *