MAT_VARWRITE(3)
π MAT_VARWRITE(3) π
okay bestie, so this is a page from the Library Functions Manual and it's literally about one little function that does one big thing: it writes your MATLAB variable into a MATLAB MAT file. no cap. let's get into it π«Ά
β¨ NAME β¨
Mat_VarWrite β writes a MATLAB variable to a MATLAB MAT file. that's it, that's the whole job description, and she does it flawlessly π
πΈ SYNOPSIS πΈ
#include <matio.h>
int
Mat_VarWrite(mat_t *matfp, matvar_t *matvar,
enum matio_compression compress);
π¦ DESCRIPTION π¦
so Mat_VarWrite() takes your MATLAB variable matvar and writes it into the MAT file matfp β and heads up, that file must already be opened for writing, okay? like, she needs the door unlocked. πͺ
if your MAT file is a version 5 or HDF5 MAT file, then the compress option lets the variable get written using zlib compression β if available, iykyk. and if compression is not available? the variable is just written uncompressed. still iconic, just chiller. π
π RETURN VALUES π
- returns
0if the variable was successfully written to the MAT file π - otherwise, an error value is returned π
π EXAMPLES π
this lil program creates a MAT file named by the first argument to the program, and writes the variable named m_pi to the file. main character behavior, honestly.
#include <math.h>
#include "matio.h"
int
main(int argc, char **argv)
{
mat_t *matfp;
matvar_t *matvar;
size_t dims[2] = {1, 1};
double m_pi = M_PI;
matfp = Mat_CreateVer(argv[1], NULL, MAT_FT_DEFAULT);
if ( NULL == matfp ) {
fprintf(stderr, "Error creating MAT file %s0, argv[1]);
return EXIT_FAILURE;
}
matvar = Mat_VarCreate("m_pi", MAT_C_DOUBLE, MAT_T_DOUBLE,
2, dims, &m_pi, 0);
if ( NULL != matvar ) {
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB);
Mat_VarFree(matvar);
}
Mat_Close(matfp);
return EXIT_SUCCESS;
}
π SEE ALSO π
fr fr, go read those too, they're the whole friend group π«
okay that's the page!! this one's from Debian, dated September 12, 2019 β¨ love that for us. mwah, go write some variables bestie ππΈπ
π¦ 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