1MAT_VARWRITE(3) BSD Library Functions Manual MAT_VARWRITE(3)
2
4 Mat_VarWrite — Writes a MATLAB variable to a MATLAB MAT file.
5
7 #include <matio.h>
8
9 int
10 Mat_VarWrite(mat_t *matfp, matvar_t *matvar,
11 enum matio_compression compress);
12
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
21 The function returns 0 if the variable was successfully written to the
22 MAT file. Otherwise, an error value is returned.
23
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,
46 2, dims, &m_pi, 0);
47 if ( NULL != matvar ) {
48 Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB);
49 Mat_VarFree(matvar);
50 }
51
52 Mat_Close(matfp);
53 return EXIT_SUCCESS;
54 }
55
56
58 Mat_CreateVer(3), Mat_Open(3), Mat_VarRead(3), Mat_VarWriteAppend(3)
59
60BSD September 12, 2019 BSD