MAT_VARCREATE(3)
π MAT_VARCREATE(3) π
okay bestie, sit down, hydrate, and let me tell you about Mat_VarCreate from the Library Functions Manual π
this is the girlie that makes your MAT variables. like, she builds the whole thing from scratch so you can yeet it into a MAT file later. main character energy fr fr π
β¨ NAME β¨
Mat_VarCreate β Creates a MAT variable structure. π¦
πΈ SYNOPSIS πΈ
#include <matio.h>
matvar_t *
Mat_VarCreate(const char *name, enum matio_classes class_type,
enum matio_types data_type, int rank, const size_t *dims,
const void *data, int opt);
π DESCRIPTION π
So Mat_VarCreate() makes a MAT structure variable called name that is fully ready to be written to a MAT file. β¨
The class_type argument says what class the variable is, and data_type says what type the data is. Like, a double-precision class would use MAT_C_DOUBLE for the class type and MAT_T_DOUBLE for the data type. π
not me about to spill the tea: in some instances the data type may not match the class type. for example, an array of integers can be written in the double-precision class by usingMAT_T_INT32fordata_type. so yeah, they're allowed to be a little mismatched, it's giving versatile π
The rank argument is how many dimensions the data has, and the number of elements in each dimension lives in the array dims. π
The data argument is a pointer to the variable data, and bestie, what it points to depends on the vibe:
- For real variables, the pointer is typically a pointer to a numeric array (e.g.
double,float,int, etc.). - For complex variables, the pointer is a pointer to a
mat_complex_split_t, which has pointers to the real and imaginary data as fields of the structure. πͺ - For sparse variables, the pointer should be a
mat_sparse_t *.
and there's opt at the end β that's your options slot, queen. π«Ά
π RETURN VALUES π
If the variable was successfully created, you get a pointer to the variable back. slay. π
Otherwise NULL is returned. π and when you're done with the variable, it should be free'd using Mat_VarFree(). don't leave her hanging, that's rude.
π EXAMPLES π
okay so here's the moment you've been waiting for. the example program below creates a MAT file named test.mat, and writes two real numeric variables x and y and a complex variable z to the file. iconic behavior honestly β¨
#include <stdlib.h>
#include <stdio.h>
#include "matio.h"
int
main(int argc,char **argv)
{
mat_t *matfp;
matvar_t *matvar;
size_t dims[2] = {10,1};
double x[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10},
y[10] = {11,12,13,14,15,16,17,18,19,20};
struct mat_complex_split_t z = {x, y};
matfp = Mat_CreateVer("test.mat", NULL, MAT_FT_DEFAULT);
if ( NULL == matfp ) {
fprintf(stderr, "Error creating MAT file
return EXIT_FAILURE;
}
matvar = Mat_VarCreate("x", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, x, 0);
if ( NULL == matvar ) {
fprintf(stderr, "Error creating variable for 'x'0);
} else {
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_NONE);
Mat_VarFree(matvar);
}
matvar = Mat_VarCreate("y", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, y, 0);
if ( NULL == matvar ) {
fprintf(stderr, "Error creating variable for 'y'0);
} else {
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_NONE);
Mat_VarFree(matvar);
}
matvar = Mat_VarCreate("z", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, &z,
MAT_F_COMPLEX);
if ( NULL == matvar ) {
fprintf(stderr, "Error creating variable for 'z'0);
} else {
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_NONE);
Mat_VarFree(matvar);
}
Mat_Close(matfp);
return EXIT_SUCCESS;
}
(and yes bestie, we copied that example character for character, no notes, no edits, periodt π )
π¦ SEE ALSO π¦
and that's the whole page, babe. this one's from Debian, dated October 26, 2025 π go forth and create your variables, you absolute legend πβ¨π«Ά
π¦ 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