MAT_VARWRITEAPPEND(3)
π MAT_VARWRITEAPPEND π
okay bestie, sit down, hydrate, and let me tell you about a little function from the matio library manual (yes, the library functions manual, we're being fancy today π). Her name is Mat_VarWriteAppend and she is literally the moment. She writes a MATLAB variable into an HDF5-format MATLAB MAT file, and β plot twist β she can append to it too. Growth mindset fr fr π±
β¨ SYNOPSIS β¨
like, this is the vibe you're importing:
#include <matio.h>
int
Mat_VarWriteAppend(mat_t *matfp, matvar_t *matvar,
enum matio_compression compress, int dim);
πΈ DESCRIPTION πΈ
So Mat_VarWriteAppend() writes β and optionally appends β the MATLAB variable matvar to the MAT file matfp, which must be opened for writing. No writing permission, no service. π
ββοΈ
And here's the juicy part: if that MATLAB variable already exists in the MAT file, the new data gets appended to it along dimension d, and d is index 1 based (so like, it starts counting at 1, not 0 β she's not like other dimensions π
).
The compress option lets the variable be written using zlib compression if it's available. And if compression is not available? She just writes it uncompressed. No drama, no crash, she simply adapts. main character energy, honestly. β¨
π«Ά RETURN VALUES π«Ά
- She returns
0when the variable was successfully written/appended to the MAT file. slay. π - Otherwise, an error value comes back. not slay, but at least she tells you. π
π¦ EXAMPLES π¦
This example program creates a MAT file named by the first argument to the program, and writes the variable named m_pi to the file in order to build a 2x1 array. (yes, she writes it twice β that's the append working its magic, bestie πͺ)
#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_MAT73);
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 ) {
int dim = 1;
Mat_VarWriteAppend(matfp, matvar, MAT_COMPRESSION_ZLIB, dim);
Mat_VarWriteAppend(matfp, matvar, MAT_COMPRESSION_ZLIB, dim);
Mat_VarFree(matvar);
}
Mat_Close(matfp);
return EXIT_SUCCESS;
}
not me pointing out that dim = 1 is doing a LOT of heavy lifting in this example, but like. it is. π
π SEE ALSO π
okay that's the whole page, you ate it, you understood it, you're basically a matio girlie now π§ββοΈπ this one comes from the Debian edition of the library functions manual, dated September 12, 2019 β so give her her flowers, she's been iconic since 2019. periodt. π π
π¦ 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