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.
To load saved variables from a MAT-file into your workspace, double-click the MAT-file in the Current Folder browser. To load a subset of variables from a MAT-file on the Home tab, in the Variable section, click Import Data. Select the MAT-file you want to load and click Open.
load( filename ) loads data from filename . If filename is a MAT-file, then load(filename) loads variables in the MAT-file into the MATLAB® workspace. If filename is an ASCII file, then load(filename) creates a double-precision array containing data from the file.
Open the Import Tool MATLAB® Toolstrip: On the Home tab, in the Variable section, click Import Data. MATLAB command prompt: Enter uiimport( filename ) , where filename is a character vector specifying the name of a text or spreadsheet file.
Use fopen to open the file, specify the character encoding, and obtain the fileID value. When you finish reading, close the file by calling fclose(fileID) . A = fscanf( fileID , formatSpec , sizeA ) reads file data into an array, A , with dimensions, sizeA , and positions the file pointer after the last value read.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With