8

I've been searching for a while to see if anyone has done any work on reading Matlab mat files in CSharp, and it seems that there is nothing out there.

Has anybody seen any solutions?

I can't simply export my mat files to text and then read them into my C# code, because there are fairly complex structures.

I don't like to inter operate with Matlab and I don't want to use Python (SciPy with loadmat) either.

Ali
  • 18,665
  • 21
  • 103
  • 138

4 Answers4

6

One option to try is the submission CSMatIO by David Zier on the MathWorks File Exchange. It's an API for .NET 2.0 that will allow you to read level 5 .mat files.

If you have to read newer .mat file formats, you can first load your .mat file into MATLAB and resave it as an older format using the SAVE function's version option.

gnovice
  • 125,304
  • 15
  • 256
  • 359
  • 1
    Alternatively, you can use a HD5 reader to get the data out of new .mat files, though you may need to put in some work. – Jonas Nov 26 '10 at 01:05
  • I just tried David Zier's libraries, they work for me, although they are not easy to work with and need a lot of twist to get my complex structures out but they are so far the best available. Thanks – Ali Nov 26 '10 at 03:53
2

ILNumerics is able to read and write to/from Matlab mat files, version 6.

2

Since CSMatIO doesn't seem to be supported, I'd like to share a link to a similar library for reading/writing MATLAB .mat files: MatFileHandler, which targets .NET Standard 2.0.

Alexander
  • 21
  • 1
1

Wanted to add another alternative. The Accord.Math library (available via Nuget, or here: http://accord-framework.net/ provides a .mat file reader.

David Hope
  • 2,216
  • 16
  • 32