1MAT_VARREAD(3) BSD Library Functions Manual MAT_VARREAD(3)
2
4 Mat_VarRead — Reads the information and data for a specific variable in a
5 MATLAB MAT file.
6
8 #include <matio.h>
9
10 matvar_t *
11 Mat_VarRead(mat_t *matfp, const char *name);
12
14 The Mat_VarRead() function reads the information and data for the vari‐
15 able name in the open MAT file.
16
18 If the variable was found in the MAT file and successfully read, a
19 pointer to the MATLAB variable structure is returned. If the variable was
20 not found, or there was an error reading the variable, NULL is returned.
21
23 This example program opens a MAT file named by the first argument to the
24 program, and reads a variable named x from the file. The matio function
25 Mat_VarPrint is used to print the information and data from the file.
26
27 #include "matio.h"
28
29 int
30 main(int argc, char **argv)
31 {
32 mat_t *matfp;
33 matvar_t *matvar;
34
35 matfp = Mat_Open(argv[1], MAT_ACC_RDONLY);
36 if ( NULL == matfp ) {
37 fprintf(stderr, "Error opening MAT file %s0, argv[1]);
38 return EXIT_FAILURE;
39 }
40
41 matvar = Mat_VarRead(matfp, "x");
42 if ( NULL != matvar ) {
43 Mat_VarPrint(matvar);
44 Mat_VarFree(matvar);
45 }
46
47 Mat_Close(matfp);
48 return EXIT_SUCCESS;
49 }
50
51
53 Mat_VarReadInfo(3), Mat_VarReadNext(3), Mat_VarPrint(3)
54
55BSD September 12, 2019 BSD