MATIO
User Manual
for version 1.5
April 2012
Christopher C. Hulbert
Copyright (C) 2011-2012 Christopher C. Hulbert . All rights reserved.
Redistribution and use in source (texinfo) and ’compiled’ forms (HTML, PDF,
PostScript, RTF and so forth) with or without modification, are permitted
provided that the following conditions are met:
1. Redistributions of source code (texinfo) must retain the above copyright
notice, this list of conditions and the following disclaimer as the
first lines of this file unmodified.
2. Redistributions in compiled form (PDF, PostScript, RTF and other
formats) must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS DOCUMENTATION IS PROVIDED BY CHRISTOPHER C. HULBERT "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL CHRISTOPHER C. HULBERT OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
i
Table of Contents
1 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 About and Licensing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Incompatible Changes from 1.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2.1 Type Change for Dimensions Array . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2.2 Removed Preprocessor Flag to Conserve Memory . . . . . . . . . . 2
1.2.3 Renamed Structure Field Lookup Enumerations . . . . . . . . . . . 2
1.2.4 Memory Conservation with Cells and Structures . . . . . . . . . . . 2
2 Quick Start. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1 Opening and Creating MAT Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Reading Variables in a MAT File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2.1 Reading a Variable by Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2.2 Iterating Over Variables in a MAT File . . . . . . . . . . . . . . . . . . . . 5
2.3 Writing Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3.1 Writing Numeric Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3.2 Writing Cell Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3.3 Writing Structure Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3 Building matio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.1 Quick Build Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.2 Configure Options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.3 Visual Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.4 Testsuite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4 MATLAB Variable Structure. . . . . . . . . . . . . . . . . 13
4.1 Variable Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.1.1 Sparse Matrix Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.1.2 Structure Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.1.3 Cell Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Chapter 1: Introduction 1
1 Introduction
1.1 About and Licensing
The matio software contains a library for reading and writing MATLAB MAT files. The ma-
tio library (libmatio) is the primary interface for creating/opening MAT files, and writing/
reading variables.
This matio software is provided with the Simplified BSD License reproduced below. The
license allows for commercial, proprietary, and open source derivative works.
Copyright 2011-2012 Christopher C. Hulbert. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY CHRISTOPHER C. HULBERT ‘‘AS IS’’ AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL CHRISTOPHER C. HULBERT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.2 Incompatible Changes from 1.3
This version has changes that break compatability with the 1.3 versions of the matio soft-
ware. This section lists these changes and how existing code should be modified to handle
these changes.
1. dims field of matvar t structure changed to size t *
2. MEM CONSERVE preprocessor definition removed
3. BY NAME and BY INDEX renamed
4. Added MAT_ prefix to enumerations of matio_compression
5. Changed name of structure for complex split-format data from struct ComplexSplit
to struct mat_complex_split_t
6. Changed name of sparse data structure from sparse_t to mat_sparse_t.
7. Changed meaning of memory conservation for cell arrays and structures