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

NAME

4     Mat_VarCreateStruct — Creates a structure variable.
5

SYNOPSIS

7     #include <matio.h>
8
9     matvar_t *
10     Mat_VarCreateStruct(const char *name, int rank, size_t *dims,
11         const char **fields, unsigned nfields);
12

DESCRIPTION

14     The Mat_VarCreateStruct() function creates a structure variable named
15     name that can be written to a MAT file.
16

RETURN VALUES

18     If the structure variable was successfully created, a pointer to the
19     variable is returned.  Otherwise NULL is returned.  The structure vari‐
20     able pointer should be free'd when no longer needed using Mat_VarFree().
21     The names of the fields are copied in the function, and thus should be
22     released after calling the function if necessary.
23

EXAMPLES

25     This example program opens a MAT file named by the first argument to the
26     program, and writes a structure named a to the file.
27
28     #include "matio.h"
29
30     int
31     main(int argc,char **argv)
32     {
33         mat_t    *matfp;
34         matvar_t *matvar;
35         matvar_t *field;
36         const char *fields[2] = {"field1","field2"};
37         double       data1 = 1, data2 = 2;
38         size_t       dims[2] = {1, 1};
39
40         matfp = Mat_Open(argv[1],MAT_ACC_RDWR);
41         if ( NULL == matfp ) {
42             fprintf(stderr,"Error opening MAT file %s0,argv[1]);
43             return EXIT_FAILURE;
44         }
45
46         dims[0] = 1; dims[1] = 1;
47         matvar = Mat_VarCreateStruct("a",2,dims,fields,2);
48         if ( NULL == matvar ) {
49             Mat_Close(matfp);
50             return EXIT_FAILURE;
51         }
52
53         field = Mat_VarCreate(NULL,MAT_C_DOUBLE,MAT_T_DOUBLE,2,dims,&data1,
54                     MAT_F_DONT_COPY_DATA);
55         Mat_VarSetStructFieldByName(matvar, "field1", 0, field);
56
57         field = Mat_VarCreate(NULL,MAT_C_DOUBLE,MAT_T_DOUBLE,2,dims,&data2,
58                     MAT_F_DONT_COPY_DATA);
59         Mat_VarSetStructFieldByName(matvar, "field2", 0, field);
60
61         Mat_VarWrite(matfp,matvar,MAT_COMPRESSION_NONE);
62         Mat_VarFree(matvar);
63
64         Mat_Close(matfp);
65         return EXIT_SUCCESS;
66     }
67

SEE ALSO

69     Mat_VarCreate(3), Mat_VarSetStructFieldByName(3)
70
71BSD                             March 18, 2012                             BSD
Impressum