Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write a MAT file without using matlab headers and libraries

I have some data that I would like to save to a MAT file (version 4 or 5, or any version, for that matter). The catch: I wanted to do this without using matlab libraries, since this code will not necessary run in a machine with matlab. My program uses Java and C++, so any existing library in those languages that achieves this could help me out...

I did some research but did not find anything in Java/C++. However, I found that scipy on python achieves this with mio4.py or mio5.py. I thought about implementing this on java or C++, but it seems a bit out of my time schedule.

So the question is: is there any libraries in Java or C/C++ that permits saving MAT files without using Matlab libraries?

Thanks a lot

like image 499
YuppieNetworking Avatar asked Apr 23 '10 16:04

YuppieNetworking


People also ask

How do I write data into a .MAT file?

Write Data Into a MAT File First, create a variable name. filename = [tempname '. mat']; Next, write that variable to a MAT-file.

How do I open a mat file without MATLAB?

It is not possible to open it with a text editor (except you have a special plugin as Dennis Jaheruddin says). Otherwise you will have to convert it into a text file (csv for example) with a script. This could be done by python for example: Read . mat files in Python.

What is .MAT file in MATLAB?

MAT-files are binary MATLAB® files that store workspace variables. Starting with MAT-file Version 4, there are several subsequent versions of MAT-files that support an increasing set of features. MATLAB releases R2006b and later all support all MAT-file versions.

What does .MAT file contain?

Files with a . mat extension contain MATLAB formatted data, and data can be loaded from or written to these files using the functions load and save , respectively. You can also access and change variables directly in MAT-files without loading them into memory using the function matfile .


2 Answers

C: matio
Java: jmatio
(I'm really tempted to, so I will, tell you to learn to google)

But really, it's not that hard to write matfiles using fwrite if you don't need to handle some of the more complex stuff (nested structs, classes, functions, sparse matrix, etc).
See: http://www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/matfile_format.pdf

like image 182
KitsuneYMG Avatar answered Oct 06 '22 09:10

KitsuneYMG


MAT files since version 7 are HDF5 based. I recall that they use some rather funny conventions, but you may be able to reverse engineer what you need. There are certainly HDF5 writing libraries for both Java and C++.

Along these lines, Matlab can read/write several standard formats, including HDF5. It may be easiest to write your data in "standard" HDF5 and read it into the desired data structure within Matlab.

like image 38
Barry Wark Avatar answered Oct 06 '22 07:10

Barry Wark