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 0 if 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