1MAT_VARWRITE(3)          BSD Library Functions Manual          MAT_VARWRITE(3)
2

NAME

4     Mat_VarWrite — Writes a MATLAB variable to a MATLAB MAT file.
5

SYNOPSIS

7     #include <matio.h>
8
9     int
10     Mat_VarWrite(mat_t *matfp, matvar_t *matvar,
11         enum matio_compression compress);
12

DESCRIPTION

14     The Mat_VarWrite() function writes the MATLAB variable matvar to the MAT
15     file matfp which must be opened for writing. If the MAT file is a version
16     5 or HDF5 MAT file, the compress option allows the variable to be written
17     using zlib compression if available.  If compression is not available,
18     the variable is written uncompressed.
19

RETURN VALUES

21     The function returns 0 if the variable was successfully written to the
22     MAT file.  Otherwise, an error value is returned.
23

EXAMPLES

25     This example program creates a MAT file named by the first argument to
26     the program, and writes the variable named m_pi to the file.
27
28     #include <math.h>
29     #include "matio.h"
30
31     int
32     main(int argc,char **argv)
33     {
34         mat_t    *matfp;
35         matvar_t *matvar;
36         size_t    dims[2] = {1,1};
37         double    m_pi = M_PI;
38
39         matfp = Mat_CreateVer(argv[1],NULL,MAT_FT_DEFAULT);
40         if ( NULL == matfp ) {
41             fprintf(stderr,"Error creating MAT file %s0,argv[1]);
42             return EXIT_FAILURE;
43         }
44
45         matvar = Mat_VarCreate("m_pi",MAT_C_DOUBLE,MAT_T_DOUBLE,2,dims,&m_pi,0);
46         if ( NULL != matvar ) {
47             Mat_VarWrite(matfp,matvar,MAT_COMPRESSION_ZLIB);
48             Mat_VarFree(matvar);
49         }
50
51         Mat_Close(matfp);
52         return EXIT_SUCCESS;
53     }
54
55

SEE ALSO

57     Mat_CreateVer(3), Mat_Open(3), Mat_VarRead(3), Mat_VarWriteAppend(3)
58
59BSD                             March 18, 2012                             BSD
Impressum