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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
// Create a new MAT file reader var reader = new MatReader("C:\Users\cdesouza\Desktop\matrix.mat"); // Let's assume the .mat file had a structure object called // "structure" on it. We can access it and its members using: var s = reader["structure"]["string"].GetValue(); // Otherwise, if we didn't know which objects were in the .MAT file, we // could have used the following to iterate over all objects in the file: foreach (var field in reader.Fields) Console.WriteLine(field.Key); // If we had that structure under the name "structure", // we could list all of its fields using: foreach (var field in structure.Fields) Console.WriteLine(field.Key); // "a", "string" // Let's say that we found out that this structure had a field called // "a". We should first determine what is the type of this field using: var aType = structure["a"].Type; // byte[,] // Now, we can retrieve the value of field "a" using byte[,] a = structure["a"].GetValue<byte[,]>(); |
To install the Accord.NET Framework into your C# application, install Accord.Math and Accord.IO through NuGet.
What good education provided in MATLAB
Is really useful
Thanks
Cesar –
Accord.net 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.
Sean
Accord.dll
Accord.IO.dll
Accord.Math.Core.dll
Accord.Math.dll
(lib/net35)
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
Accord.IO.dll
Accord.Math.Core.dll
Accord.Math.dll
(lib/net35)
Thanks for any help!
Great post..was helpful to understand matlab
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.
Best,
Ahmad
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 . . .
Hi Cesar,
how does the format of your .mat file look like?
Thanks in advance 🙂