MAT_VARCREATESTRUCT(3)
π MAT_VARCREATESTRUCT(3) π
okay bestie, welcome to the Library Functions Manual page for Mat_VarCreateStruct π«Ά this is a matio situation and we're gonna get through it together, no cap.
β¨ NAME β¨
Mat_VarCreateStruct β literally creates a structure variable. that's the whole job. queen behavior.
πΈ SYNOPSIS πΈ
#include <matio.h>
matvar_t *
Mat_VarCreateStruct(const char *name, int rank, const size_t *dims,
const char *const *fields, unsigned nfields);
π¦ DESCRIPTION π¦
so the Mat_VarCreateStruct() function creates a structure variable named name that can be written to a MAT file. that's it, that's the vibe. you hand it a name, a rank, some dims, a list of fields and how many of them there are (nfields), and it gives you back a whole structure variable. iconic.
π RETURN VALUES π
if the structure variable was successfully created, you get a pointer to the variable back. slay. π
otherwise you get NULL. no variable, no vibes, nothing. π
the structure variable pointer should be free'd when no longer needed, using Mat_VarFree(). don't forget, bestie, that's a memory leak otherwise and we do not do that here.
also important: the names of the fields are copied in the function, and thus should be released after calling the function if necessary. so your originals are yours to deal with.
π¨ okay serious moment: this function is deprecated since version 1.5.30. use Mat_VarCreateStruct2 instead. i'm not saying it to be mean, i'm saying it because i love you. π
π EXAMPLES π
this example program opens a MAT file named by the first argument to the program, and writes a structure named a to the file. let's gooo.
#include "matio.h"
int
main(int argc, char **argv)
{
mat_t *matfp;
matvar_t *matvar;
matvar_t *field;
const char *fields[2] = {"field1", "field2"};
double data1 = 1, data2 = 2;
size_t dims[2] = {1, 1};
matfp = Mat_Open(argv[1], MAT_ACC_RDWR);
if ( NULL == matfp ) {
fprintf(stderr, "Error opening MAT file %s0, argv[1]);
return EXIT_FAILURE;
}
dims[0] = 1; dims[1] = 1;
matvar = Mat_VarCreateStruct("a", 2, dims, fields, 2);
if ( NULL == matvar ) {
Mat_Close(matfp);
return EXIT_FAILURE;
}
field = Mat_VarCreate(NULL, MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, &data1,
MAT_F_DONT_COPY_DATA);
Mat_VarSetStructFieldByName(matvar, "field1", 0, field);
field = Mat_VarCreate(NULL, MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, &data2,
MAT_F_DONT_COPY_DATA);
Mat_VarSetStructFieldByName(matvar, "field2", 0, field);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_NONE);
Mat_VarFree(matvar);
Mat_Close(matfp);
return EXIT_SUCCESS;
}
see how it all comes together? open, create, set the fields, write, free, close. a whole little routine and it ate. π₯
π SEE ALSO π
Mat_VarCreateStruct2(3)Mat_VarCreate(3)Mat_VarSetStructFieldByName(3)
and that's the page, bestie π this one came to you from Debian, dated January 5, 2026, and it lives under the name MAT_VARCREATESTRUCT(3). go forth and make structures. mwah. πβ¨
π¦ where this page comes from
- arch rolling: libmatio 1.5.30-1 Β· BSD-2-Clause
- fedora 44: matio-devel 1.5.30-2.fc44 Β· BSD-2-Clause
- fedora 44: matio-devel 1.5.30-2.fc44 Β· BSD-2-Clause
- nixpkgs unstable: matio 1.5.30
- ubuntu resolute: libmatio-doc 1.5.30-2 Β· BSD-2-Clause
- ubuntu stonking: libmatio-doc 1.5.30-4build1 Β· BSD-2-Clause
- Copyright (c) 2015-2026, The matio contributors
- Copyright (c) 2012-2014, Christopher C. Hulbert
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms