Matlab MAT File I/O Library


Data Structures

struct  ComplexSplit
 Complex data type using split storage. More...
struct  mat_t
 Matlab MAT File information. More...
struct  matvar_t
 Matlab variable information. More...
struct  sparse_t
 sparse data information More...

Files

file  inflate.c
 Functions to inflate data/tags.
file  io.c
file  mat.c
file  mat4.c
file  mat5.c
file  matio.h
file  read_data.c

Enumerations

enum  { BY_NAME = 1, BY_INDEX = 2 }
enum  mat_acc { MAT_ACC_RDONLY = 1, MAT_ACC_RDWR = 2 }
 MAT file access types. More...
enum  mat_ft { MAT_FT_MAT5 = 1, MAT_FT_MAT4 = 1 << 16 }
 MAT file versions. More...
enum  matio_classes {
  MAT_C_CELL = 1, MAT_C_STRUCT = 2, MAT_C_OBJECT = 3, MAT_C_CHAR = 4,
  MAT_C_SPARSE = 5, MAT_C_DOUBLE = 6, MAT_C_SINGLE = 7, MAT_C_INT8 = 8,
  MAT_C_UINT8 = 9, MAT_C_INT16 = 10, MAT_C_UINT16 = 11, MAT_C_INT32 = 12,
  MAT_C_UINT32 = 13, MAT_C_INT64 = 14, MAT_C_UINT64 = 15, MAT_C_FUNCTION = 16
}
 Matlab variable classes. More...
enum  matio_compression { COMPRESSION_NONE = 0, COMPRESSION_ZLIB = 1 }
 Matlab compression options. More...
enum  matio_flags { MAT_F_COMPLEX = 0x0800, MAT_F_GLOBAL = 0x0400, MAT_F_LOGICAL = 0x0200, MAT_F_CLASS_T = 0x00ff }
 Matlab array flags. More...
enum  matio_types {
  MAT_T_UNKNOWN = 0, MAT_T_INT8 = 1, MAT_T_UINT8 = 2, MAT_T_INT16 = 3,
  MAT_T_UINT16 = 4, MAT_T_INT32 = 5, MAT_T_UINT32 = 6, MAT_T_SINGLE = 7,
  MAT_T_DOUBLE = 9, MAT_T_INT64 = 12, MAT_T_UINT64 = 13, MAT_T_MATRIX = 14,
  MAT_T_COMPRESSED = 15, MAT_T_UTF8 = 16, MAT_T_UTF16 = 17, MAT_T_UTF32 = 18,
  MAT_T_STRING = 20, MAT_T_CELL = 21, MAT_T_STRUCT = 22, MAT_T_ARRAY = 23,
  MAT_T_FUNCTION = 24
}
 Matlab data types. More...

Functions

int Mat_CalcSingleSubscript (int rank, int *dims, int *subs)
 Calculate a single subscript from a set of subscript values.
int * Mat_CalcSubscripts (int rank, int *dims, int index)
 Calculate a set of subscript values from a single(linear) subscript.
int Mat_Close (mat_t *mat)
 Closes an open Matlab MAT file.
mat_tMat_Create (const char *matname, const char *hdr_str)
 Creates a new Matlab MAT file.
mat_tMat_Open (const char *matname, int mode)
 Opens an existing Matlab MAT file.
int Mat_Rewind (mat_t *mat)
 Rewinds a Matlab MAT file to the first variable.
size_t Mat_SizeOfClass (int class_type)
 Returns the size of a Matlab Class.
int Mat_VarAddStructField (matvar_t *matvar, matvar_t **fields)
 Adds a field to a structure.
matvar_tMat_VarCalloc (void)
 Allocates memory for a new matvar_t and initializes all the fields.
matvar_tMat_VarCreate (const char *name, int class_type, int data_type, int rank, int *dims, void *data, int opt)
 Creates a MAT Variable with the given name and (optionally) data.
int Mat_VarDelete (mat_t *mat, char *name)
 Deletes a variable from a file.
matvar_tMat_VarDuplicate (const matvar_t *in, int opt)
 Duplicates a matvar_t structure.
void Mat_VarFree (matvar_t *matvar)
 Frees all the allocated memory associated with the structure.
matvar_tMat_VarGetCell (matvar_t *matvar, int index)
 Returns a pointer to the Cell array at a specific index.
matvar_t ** Mat_VarGetCells (matvar_t *matvar, int *start, int *stride, int *edge)
 Indexes a cell array.
matvar_t ** Mat_VarGetCellsLinear (matvar_t *matvar, int start, int stride, int edge)
 Indexes a cell array.
int Mat_VarGetNumberOfFields (matvar_t *matvar)
 Returns the number of fields in a structure variable.
size_t Mat_VarGetSize (matvar_t *matvar)
 Calculates the size of a matlab variable in bytes.
matvar_tMat_VarGetStructField (matvar_t *matvar, void *name_or_index, int opt, int index)
 Finds a field of a structure.
matvar_tMat_VarGetStructs (matvar_t *matvar, int *start, int *stride, int *edge, int copy_fields)
 Indexes a structure.
matvar_tMat_VarGetStructsLinear (matvar_t *matvar, int start, int stride, int edge, int copy_fields)
 Indexes a structure.
void Mat_VarPrint (matvar_t *matvar, int printdata)
 Prints the variable information.
matvar_tMat_VarRead (mat_t *mat, char *name)
 Reads the variable with the given name from a MAT file.
int Mat_VarReadData (mat_t *mat, matvar_t *matvar, void *data, int *start, int *stride, int *edge)
 Reads MAT variable data from a file.
int Mat_VarReadDataAll (mat_t *mat, matvar_t *matvar)
 Reads all the data for a matlab variable.
int Mat_VarReadDataLinear (mat_t *mat, matvar_t *matvar, void *data, int start, int stride, int edge)
 Reads MAT variable data from a file.
matvar_tMat_VarReadInfo (mat_t *mat, char *name)
 Reads the information of a variable with the given name from a MAT file.
matvar_tMat_VarReadNext (mat_t *mat)
 Reads the next variable in a MAT file.
matvar_tMat_VarReadNextInfo (mat_t *mat)
 Reads the information of the next variable in a MAT file.
int Mat_VarWrite (mat_t *mat, matvar_t *matvar, int compress)
 Writes the given MAT variable to a MAT file.
int Mat_VarWriteData (mat_t *mat, matvar_t *matvar, void *data, int *start, int *stride, int *edge)
 Writes the given data to the MAT variable.
int Mat_VarWriteInfo (mat_t *mat, matvar_t *matvar)
 Writes the given MAT variable to a MAT file.

Detailed Description


Enumeration Type Documentation

anonymous enum

matio lookup type

Enumerator:
BY_NAME  Lookup by name
BY_INDEX  Lookup by index

enum mat_acc

MAT file access types

Enumerator:
MAT_ACC_RDONLY  Read only file access.
MAT_ACC_RDWR  Read/Write file access.

enum mat_ft

MAT file versions

Enumerator:
MAT_FT_MAT5  Matlab level-5 file.
MAT_FT_MAT4  Version 4 file.

Matlab variable classes

Enumerator:
MAT_C_CELL  Matlab cell array class.
MAT_C_STRUCT  Matlab structure class.
MAT_C_OBJECT  Matlab object class.
MAT_C_CHAR  Matlab character array class.
MAT_C_SPARSE  Matlab sparse array class.
MAT_C_DOUBLE  Matlab double-precision class.
MAT_C_SINGLE  Matlab single-precision class.
MAT_C_INT8  Matlab signed 8-bit integer class.
MAT_C_UINT8  Matlab unsigned 8-bit integer class.
MAT_C_INT16  Matlab signed 16-bit integer class.
MAT_C_UINT16  Matlab unsigned 16-bit integer class.
MAT_C_INT32  Matlab signed 32-bit integer class.
MAT_C_UINT32  Matlab unsigned 32-bit integer class.
MAT_C_INT64  Matlab unsigned 32-bit integer class.
MAT_C_UINT64  Matlab unsigned 32-bit integer class.
MAT_C_FUNCTION  Matlab unsigned 32-bit integer class.

Matlab compression options

Enumerator:
COMPRESSION_NONE  No compression.
COMPRESSION_ZLIB  zlib compression

Matlab array flags

Enumerator:
MAT_F_COMPLEX  Complex bit flag.
MAT_F_GLOBAL  Global bit flag.
MAT_F_LOGICAL  Logical bit flag.
MAT_F_CLASS_T  Class-Type bits flag.

Matlab data types

Enumerator:
MAT_T_UNKNOWN  UNKOWN data type.
MAT_T_INT8  8-bit signed integer data type
MAT_T_UINT8  8-bit unsigned integer data type
MAT_T_INT16  16-bit signed integer data type
MAT_T_UINT16  16-bit unsigned integer data type
MAT_T_INT32  32-bit signed integer data type
MAT_T_UINT32  32-bit unsigned integer data type
MAT_T_SINGLE  IEEE 754 single precision data type.
MAT_T_DOUBLE  IEEE 754 double precision data type.
MAT_T_INT64  64-bit signed integer data type
MAT_T_UINT64  64-bit unsigned integer data type
MAT_T_MATRIX  matrix data type
MAT_T_COMPRESSED  compressed data type
MAT_T_UTF8  8-bit unicode text data type
MAT_T_UTF16  16-bit unicode text data type
MAT_T_UTF32  32-bit unicode text data type
MAT_T_STRING  String data type.
MAT_T_CELL  Cell array data type.
MAT_T_STRUCT  Structure data type.
MAT_T_ARRAY  Array data type.
MAT_T_FUNCTION  Function data type.


Function Documentation

int Mat_CalcSingleSubscript ( int  rank,
int *  dims,
int *  subs 
)

Calculates a single linear subscript (0-relative) given a 1-relative subscript for each dimension. The calculation uses the formula below where index is the linear index, s is an array of length RANK where each element is the subscript for the correspondind dimension, D is an array whose elements are the dimensions of the variable.

\[ index = \sum\limits_{k=0}^{RANK-1} [(s_k - 1) \prod\limits_{l=0}^{k} D_l ] \]

Parameters:
rank Rank of the variable
dims dimensions of the variable
subs Dimension subscripts
Returns:
Single (linear) subscript

int* Mat_CalcSubscripts ( int  rank,
int *  dims,
int  index 
)

Calculates 1-relative subscripts for each dimension given a 0-relative linear index. Subscripts are calculated as follows where s is the array of dimension subscripts, D is the array of dimensions, and index is the linear index.

\[ s_k = \lfloor\frac{1}{L} \prod\limits_{l = 0}^{k} D_l\rfloor + 1 \]

\[ L = index - \sum\limits_{l = k}^{RANK - 1} s_k \prod\limits_{m = 0}^{k} D_m \]

Parameters:
rank Rank of the variable
dims dimensions of the variable
index linear index
Returns:
Array of dimension subscripts

int Mat_Close ( mat_t mat  ) 

Closes the given Matlab MAT file and frees any memory with it.

Parameters:
mat Pointer to the MAT file
Return values:
0 

References mat_t::filename, mat_t::fp, mat_t::header, and mat_t::subsys_offset.

Referenced by Mat_Open(), and Mat_VarDelete().

mat_t* Mat_Create ( const char *  matname,
const char *  hdr_str 
)

Tries to create a new Matlab MAT file with the given name and optional header string. If no header string is given, the default string is used containing the software, version, and date in it. If a header string is given, at most the first 116 characters is written to the file. The given header string need not be the full 116 characters, but MUST be NULL terminated.

Parameters:
matname Name of MAT file to create
hdr_str Optional header string, NULL to use default
Returns:
A pointer to the MAT file or NULL if it failed. This is not a simple FILE * and should not be used as one.

References mat_t::bof, mat_t::byteswap, mat_t::filename, mat_t::fp, mat_t::header, MAT_ACC_RDWR, mat_t::mode, mat_t::subsys_offset, and mat_t::version.

Referenced by Mat_Open(), and Mat_VarDelete().

mat_t* Mat_Open ( const char *  matname,
int  mode 
)

Tries to open a Matlab MAT file with the given name

Parameters:
matname Name of MAT file to open
mode File access mode (MAT_ACC_RDONLY,MAT_ACC_RDWR,etc).
Returns:
A pointer to the MAT file or NULL if it failed. This is not a simple FILE * and should not be used as one.

References mat_t::bof, mat_t::byteswap, mat_t::filename, mat_t::fp, mat_t::header, MAT_ACC_RDONLY, MAT_ACC_RDWR, Mat_Close(), Mat_Create(), MAT_FT_MAT4, Mat_int16Swap(), mat_t::mode, mat_t::subsys_offset, and mat_t::version.

Referenced by Mat_VarDelete().

int Mat_Rewind ( mat_t mat  ) 

Rewinds a Matlab MAT file to the first variable

Parameters:
mat Pointer to the MAT file
Return values:
0 on success

References mat_t::fp, MAT_FT_MAT4, and mat_t::version.

size_t Mat_SizeOfClass ( int  class_type  ) 

Returns the size (in bytes) of the matlab class class_type

Parameters:
class_type Matlab class type (MAT_C_*)
Returns:
Size of the class

References MAT_C_CHAR, MAT_C_DOUBLE, MAT_C_INT16, MAT_C_INT32, MAT_C_INT64, MAT_C_INT8, MAT_C_SINGLE, MAT_C_UINT16, MAT_C_UINT32, MAT_C_UINT64, and MAT_C_UINT8.

Referenced by Mat_VarGetSize().

int Mat_VarAddStructField ( matvar_t matvar,
matvar_t **  fields 
)

Adds the given field to the structure. fields should be an array of matvar_t pointers of the same size as the structure (i.e. 1 field per structure element).

Parameters:
matvar Pointer to the Structure MAT variable
fields Array of fields to be added
Return values:
0 on success

References matvar_t::data, matvar_t::dims, matvar_t::nbytes, and matvar_t::rank.

matvar_t* Mat_VarCalloc ( void   ) 

matvar_t* Mat_VarCreate ( const char *  name,
int  class_type,
int  data_type,
int  rank,
int *  dims,
void *  data,
int  opt 
)

Creates a MAT variable that can be written to a Matlab MAT file with the given name, data type, dimensions and data. Rank should always be 2 or more. i.e. Scalar values would have rank=2 and dims[2] = {1,1}. Data type is one of the MAT_T types. MAT adds MAT_T_STRUCT and MAT_T_CELL to create Structures and Cell Arrays respectively. For MAT_T_STRUCT, data should be a NULL terminated array of matvar_t * variables (i.e. for a 3x2 structure with 10 fields, there should be 61 matvar_t * variables where the last one is NULL). For cell arrays, the NULL termination isn't necessary. So to create a cell array of size 3x2, data would be the address of an array of 6 matvar_t * variables.

EXAMPLE: To create a struct of size 3x2 with 3 fields:

     int rank=2, dims[2] = {3,2}, nfields = 3;
     matvar_t **vars;

     vars = malloc((3*2*nfields+1)*sizeof(matvar_t *));
     vars[0]             = Mat_VarCreate(...);
        :
     vars[3*2*nfields-1] = Mat_VarCreate(...);
     vars[3*2*nfields]   = NULL;

EXAMPLE: To create a cell array of size 3x2:

     int rank=2, dims[2] = {3,2};
     matvar_t **vars;

     vars = malloc(3*2*sizeof(matvar_t *));
     vars[0]             = Mat_VarCreate(...);
        :
     vars[5] = Mat_VarCreate(...);

Parameters:
name Name of the variable to create
class_type class type of the variable in Matlab(one of the mx Classes)
data_type data type of the variable (one of the MAT_T_ Types)
rank Rank of the variable
dims array of dimensions of the variable of size rank
data pointer to the data
opt 0, or bitwise or of the following options:
  • MEM_CONSERVE to just use the pointer to the data and not copy the data itself. Note that the pointer should not be freed until you are done with the mat variable. The Mat_VarFree function will NOT free data that was created with MEM_CONSERVE, so free it yourself.
  • MAT_F_COMPLEX to specify that the data is complex. The data variable should be a contigouse piece of memory with the real part written first and the imaginary second
  • MAT_F_GLOBAL to assign the variable as a global variable
  • MAT_F_LOGICAL to specify that it is a logical variable
Returns:
A MAT variable that can be written to a file or otherwise used

References matvar_t::class_type, matvar_t::compression, COMPRESSION_NONE, matvar_t::data, matvar_t::data_size, matvar_t::data_type, matvar_t::dims, ComplexSplit::Im, matvar_t::isComplex, matvar_t::isGlobal, matvar_t::isLogical, MAT_C_CHAR, MAT_C_SPARSE, MAT_F_COMPLEX, MAT_F_GLOBAL, MAT_F_LOGICAL, MAT_T_CELL, MAT_T_DOUBLE, MAT_T_INT16, MAT_T_INT32, MAT_T_INT64, MAT_T_INT8, MAT_T_SINGLE, MAT_T_STRUCT, MAT_T_UINT16, MAT_T_UINT32, MAT_T_UINT64, MAT_T_UINT8, MAT_T_UTF16, MAT_T_UTF32, MAT_T_UTF8, Mat_VarCalloc(), Mat_VarFree(), matvar_t::mem_conserve, matvar_t::name, matvar_t::nbytes, matvar_t::rank, and ComplexSplit::Re.

int Mat_VarDelete ( mat_t mat,
char *  name 
)

Parameters:
mat Pointer to the mat_t file structure
name Name of the variable to delete
Returns:
0 on success

References mat_t::filename, mat_t::fp, mat_t::header, Mat_Close(), Mat_Create(), Mat_Open(), Mat_VarFree(), Mat_VarReadNext(), Mat_VarWrite(), mat_t::mode, and matvar_t::name.

matvar_t* Mat_VarDuplicate ( const matvar_t in,
int  opt 
)

Provides a clean function for duplicating a matvar_t structure.

Parameters:
in pointer to the matvar_t structure to be duplicated
opt 0 does a shallow duplicate and only assigns the data pointer to the duplicated array. 1 will do a deep duplicate and actually duplicate the contents of the data. Warning: If you do a shallow copy and free both structures, the data will be freed twice and memory will be corrupted. This may be fixed in a later release.
Returns:
Pointer to the duplicated matvar_t structure.

References matvar_t::class_type, matvar_t::compression, matvar_t::data, matvar_t::data_size, matvar_t::data_type, matvar_t::datapos, matvar_t::dims, matvar_t::fpos, ComplexSplit::Im, matvar_t::isComplex, matvar_t::isGlobal, matvar_t::isLogical, MAT_C_CELL, MAT_C_STRUCT, Mat_VarDuplicate(), matvar_t::mem_conserve, matvar_t::name, matvar_t::nbytes, matvar_t::rank, ComplexSplit::Re, and matvar_t::z.

Referenced by Mat_VarDuplicate(), Mat_VarGetStructs(), and Mat_VarGetStructsLinear().

void Mat_VarFree ( matvar_t matvar  ) 

matvar_t* Mat_VarGetCell ( matvar_t matvar,
int  index 
)

Returns a pointer to the Cell Array Field at the given 1-relative index. MAT file must be a version 5 matlab file.

Parameters:
matvar Pointer to the Cell Array MAT variable
index linear index of cell to return
Returns:
Pointer to the Cell Array Field on success, NULL on error

References matvar_t::data, matvar_t::dims, and matvar_t::rank.

matvar_t** Mat_VarGetCells ( matvar_t matvar,
int *  start,
int *  stride,
int *  edge 
)

Finds cells of a cell array given a start, stride, and edge for each. dimension. The cells are placed in a pointer array. The cells should not be freed, but the array of pointers should be. If copies are needed, use Mat_VarDuplicate on each cell. MAT File version must be 5.

Parameters:
matvar Cell Array matlab variable
start vector of length rank with 0-relative starting coordinates for each diemnsion.
stride vector of length rank with strides for each diemnsion.
edge vector of length rank with the number of elements to read in each diemnsion.
Returns:
an array of pointers to the cells

References matvar_t::data, matvar_t::dims, and matvar_t::rank.

matvar_t** Mat_VarGetCellsLinear ( matvar_t matvar,
int  start,
int  stride,
int  edge 
)

Finds cells of a cell array given a linear indexed start, stride, and edge. The cells are placed in a pointer array. The cells themself should not be freed as they are part of the original cell array, but the pointer array should be. If copies are needed, use Mat_VarDuplicate on each of the cells. MAT file version must be 5.

Parameters:
matvar Cell Array matlab variable
start starting index
stride stride
edge Number of cells to get
Returns:
an array of pointers to the cells

References matvar_t::data, and matvar_t::rank.

int Mat_VarGetNumberOfFields ( matvar_t matvar  ) 

Returns the number of fields in the given structure. MAT file version must be 5.

Parameters:
matvar Structure matlab variable
Returns:
Number of fields, or a negative number on error

References matvar_t::class_type, matvar_t::data_size, matvar_t::dims, MAT_C_STRUCT, matvar_t::nbytes, and matvar_t::rank.

size_t Mat_VarGetSize ( matvar_t matvar  ) 

Parameters:
matvar matlab variable
Returns:
size of the variable in bytes

References matvar_t::class_type, matvar_t::data, matvar_t::data_size, matvar_t::dims, MAT_C_CELL, MAT_C_STRUCT, Mat_SizeOfClass(), Mat_VarGetSize(), matvar_t::nbytes, and matvar_t::rank.

Referenced by Mat_VarGetSize().

matvar_t* Mat_VarGetStructField ( matvar_t matvar,
void *  name_or_index,
int  opt,
int  index 
)

Returns a pointer to the structure field at the given 0-relative index. MAT file version must be 5.

Parameters:
matvar Pointer to the Structure MAT variable
name_or_index Name of the field, or the 1-relative index of the field. If the index is used, it should be the address of an integer variable whose value is the index number.
opt BY_NAME if the name_or_index is the name or BY_INDEX if the index was passed.
index linear index of the structure to find the field of
Returns:
Pointer to the Structure Field on success, NULL on error

References BY_INDEX, BY_NAME, matvar_t::data, matvar_t::dims, matvar_t::name, matvar_t::nbytes, and matvar_t::rank.

matvar_t* Mat_VarGetStructs ( matvar_t matvar,
int *  start,
int *  stride,
int *  edge,
int  copy_fields 
)

Finds structures of a structure array given a start, stride, and edge for each dimension. The structures are placed in a new structure array. If copy_fields is non-zero, the indexed structures are copied and should be freed, but if copy_fields is zero, the indexed structures are pointers to the original, but should still be freed since the mem_conserve flag is set so that the structures are not freed. MAT File version must be 5.

Parameters:
matvar Structure matlab variable
start vector of length rank with 0-relative starting coordinates for each diemnsion.
stride vector of length rank with strides for each diemnsion.
edge vector of length rank with the number of elements to read in each diemnsion.
copy_fields 1 to copy the fields, 0 to just set pointers to them. If 0 is used, the fields should not be freed themselves.
Returns:
A new structure with fields indexed from matvar.

References matvar_t::class_type, matvar_t::data, matvar_t::data_size, matvar_t::dims, MAT_C_STRUCT, Mat_VarDuplicate(), Mat_VarFree(), matvar_t::mem_conserve, matvar_t::nbytes, and matvar_t::rank.

matvar_t* Mat_VarGetStructsLinear ( matvar_t matvar,
int  start,
int  stride,
int  edge,
int  copy_fields 
)

Finds structures of a structure array given a single (linear)start, stride, and edge. The structures are placed in a new structure array. If copy_fields is non-zero, the indexed structures are copied and should be freed, but if copy_fields is zero, the indexed structures are pointers to the original, but should still be freed since the mem_conserve flag is set so that the structures are not freed. MAT File version must be 5.

Parameters:
matvar Structure matlab variable
start starting index
stride stride
edge Number of structures to get
copy_fields 1 to copy the fields, 0 to just set pointers to them. If 0 is used, the fields should not be freed themselves.
Returns:
A new structure with fields indexed from matvar

References matvar_t::data, matvar_t::data_size, matvar_t::dims, Mat_VarDuplicate(), matvar_t::mem_conserve, matvar_t::nbytes, and matvar_t::rank.

void Mat_VarPrint ( matvar_t matvar,
int  printdata 
)

Prints to stdout the values of the matvar_t structure

Parameters:
matvar Pointer to the matvar_t structure
printdata set to 1 if the Variables data should be printed, else 0

References matvar_t::fp, MAT_FT_MAT4, Mat_VarPrint5(), and mat_t::version.

Referenced by Mat_VarPrint5().

matvar_t* Mat_VarRead ( mat_t mat,
char *  name 
)

Reads the next variable in the Matlab MAT file

Parameters:
mat Pointer to the MAT file
name Name of the variable to read
Returns:
Pointer to the matvar_t structure containing the MAT variable information

References mat_t::fp, and Mat_VarReadInfo().

int Mat_VarReadData ( mat_t mat,
matvar_t matvar,
void *  data,
int *  start,
int *  stride,
int *  edge 
)

Reads data from a MAT variable. The variable must have been read by Mat_VarReadInfo.

Parameters:
mat MAT file to read data from
matvar MAT variable information
data pointer to store data in (must be pre-allocated)
start array of starting indeces
stride stride of data
edge array specifying the number to read in each direction
Return values:
0 on success

References MAT_FT_MAT4, ReadData5(), and mat_t::version.

int Mat_VarReadDataAll ( mat_t mat,
matvar_t matvar 
)

Allocates memory for an reads the data for a given matlab variable.

Parameters:
mat Matlab MAT file structure pointer
matvar Variable whose data is to be read
Returns:
non-zero on error

int Mat_VarReadDataLinear ( mat_t mat,
matvar_t matvar,
void *  data,
int  start,
int  stride,
int  edge 
)

matvar_t* Mat_VarReadInfo ( mat_t mat,
char *  name 
)

Reads the named variable (or the next variable if name is NULL) information (class,flags-complex/global/logical,rank,dimensions,and name) from the Matlab MAT file

Parameters:
mat Pointer to the MAT file
name Name of the variable to read
Returns:
Pointer to the matvar_t structure containing the MAT variable information

References mat_t::bof, mat_t::byteswap, mat_t::fp, Mat_int32Swap(), Mat_VarFree(), Mat_VarReadNextInfo(), and matvar_t::name.

Referenced by Mat_VarRead().

matvar_t* Mat_VarReadNext ( mat_t mat  ) 

Reads the next variable in the Matlab MAT file

Parameters:
mat Pointer to the MAT file
Returns:
Pointer to the matvar_t structure containing the MAT variable information

References mat_t::fp, and Mat_VarReadNextInfo().

Referenced by Mat_VarDelete().

matvar_t* Mat_VarReadNextInfo ( mat_t mat  ) 

Reads the next variable's information (class,flags-complex/global/logical, rank,dimensions, name, etc) from the Matlab MAT file. After reading, the MAT file is positioned past the current variable.

Parameters:
mat Pointer to the MAT file
Returns:
Pointer to the matvar_t structure containing the MAT variable information

References Mat_VarReadNextInfo5(), and mat_t::version.

Referenced by Mat_VarReadInfo(), Mat_VarReadNext(), and ReadNextFunctionHandle().

int Mat_VarWrite ( mat_t mat,
matvar_t matvar,
int  compress 
)

Writes the MAT variable information stored in matvar to the given MAT file. The variable will be written to the end of the file.

Parameters:
mat MAT file to write to
matvar MAT variable information to write
compress Whether or not to compress the data (Only valid for version 5 MAT files and variables with numeric data)
Return values:
0 on success

References MAT_FT_MAT4, mat_t::version, and Write5().

Referenced by Mat_VarDelete().

int Mat_VarWriteData ( mat_t mat,
matvar_t matvar,
void *  data,
int *  start,
int *  stride,
int *  edge 
)

Writes data to a MAT variable. The variable must have previously been written with Mat_VarWriteInfo.

Parameters:
mat MAT file to write to
matvar MAT variable information to write
data pointer to the data to write
start array of starting indeces
stride stride of data
edge array specifying the number to read in each direction
Return values:
0 on success

References matvar_t::class_type, matvar_t::compression, COMPRESSION_NONE, COMPRESSION_ZLIB, matvar_t::data_type, matvar_t::datapos, matvar_t::dims, mat_t::fp, MAT_C_CHAR, MAT_C_DOUBLE, MAT_C_INT16, MAT_C_INT32, MAT_C_INT64, MAT_C_INT8, MAT_C_SINGLE, MAT_C_UINT16, MAT_C_UINT32, MAT_C_UINT64, MAT_C_UINT8, matvar_t::rank, WriteCharDataSlab2(), WriteData(), WriteDataSlab2(), and matvar_t::z.

int Mat_VarWriteInfo ( mat_t mat,
matvar_t matvar 
)

Writes the MAT variable information stored in matvar to the given MAT file. The variable will be written to the end of the file.

Parameters:
mat MAT file to write to
matvar MAT variable information to write
Return values:
0 on success

References mat_t::fp, MAT_FT_MAT4, mat_t::version, and WriteInfo5().


Generated on Sun Jul 26 20:59:00 2009 for LIBMATIO API by  doxygen 1.5.9