I'd like to convert some MAT files to XML (each .mat file contains a hierarchical structure) so I can access the data from other software (like R, Python). These MAT files were generated in Matlab 6.5 so they are not in the HDF5 data format specification. There is a user-contributed XML toolbox (from 2003) which suggests a simple conversion from MAT to XML is possible:
http://www.mathworks.com/matlabcentral/fileexchange/4278
but I seem to run into an error with the xml_format function:
??? NaN's cannot be converted to logicals.
The data structure I am trying to convert is nested on many levels with many data types (arrays, etc.), so I may have to write my own exporting function. I am using Matlab Version 7.10.0.499 (R2010a) 64-bit (maci64) so I should have the xmlwrite
and xmlread
functions available to me:
http://www.mathworks.com/help/techdoc/import_export/f5-86078.html#bsmnj5u
However, when I try to follow their example,
docNode = com.mathworks.xml.XMLUtils.createDocument('root_element')
I get an error:
??? Undefined variable "com" or class
If I try to see which java classes are loaded, I get
[M,X,J] = 开发者_开发百科inmem;
J =
'MException'
though in my $matlabroot/toolbox/local/classpath.txt
there appear to be a lot of Java classes loaded.
Do I need to install Java modules or add additional paths, or something else to get this to working? Or do you have any suggestions to go from MAT to another common data exchange format that allows arbitrary nesting of structures (some of which contain array representation of images)? I have not seen much in the way of MAT to HDF5 conversion, which seems like it could also be a reasonable alternative to going from MAT to XML... Thanks ~
Since newer mat files are just HDF5 files with rows/cols flipped you could just write new matlabs to get it into HDF5.
To convert the old mat files to the newer HDF5 format just open them in matlab and resave
s=open('AFile.mat')
save('AFile.mat','-struct','s')
or so
You can also explore the hdf5write
function
精彩评论