MAT_VARREAD(3)

πŸ’– MAT_VARREAD(3) πŸ’–

ok so bestie, we're in the Library Functions Manual section of your terminal and today's main character is Mat_VarRead β€” no cap, she's the one who actually goes and gets your data. 🫢


✨ NAME ✨

Mat_VarRead β€” literally reads the information and the data for one specific variable inside a MATLAB MAT file. both. the whole thing. slay. πŸ’…


🌸 SYNOPSIS 🌸

#include <matio.h>

matvar_t *
Mat_VarRead(mat_t *matfp, const char *name);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the vibe: the Mat_VarRead() function reads the information and the data for the variable name in the open MAT file. that's it, that's the whole job, and she does it flawlessly. ✨


πŸ’œ RETURN VALUES πŸ’œ

  • if the variable was found in the MAT file and successfully read β†’ you get back a pointer to the MATLAB variable structure. iconic. πŸ‘‘
  • if the variable was not found, or if there was an error reading the variable β†’ you get NULL. 😭
bestie, pls always check for NULL, it's giving "I forgot to check and now everything is on fire". πŸ”₯

πŸŽ€ EXAMPLES πŸŽ€

ok so this example program opens a MAT file named by the first argument to the program, and reads a variable named x from the file. and because she's extra, she uses the matio function Mat_VarPrint to print the information and data from the file. 🌈

#include "matio.h"

int
main(int argc, char **argv)
{
    mat_t    *matfp;
    matvar_t *matvar;

    matfp = Mat_Open(argv[1], MAT_ACC_RDONLY);
    if ( NULL == matfp ) {
        fprintf(stderr, "Error opening MAT file %s0, argv[1]);
        return EXIT_FAILURE;
    }

    matvar = Mat_VarRead(matfp, "x");
    if ( NULL != matvar ) {
        Mat_VarPrint(matvar);
        Mat_VarFree(matvar);
    }

    Mat_Close(matfp);
    return EXIT_SUCCESS;
}

🧚 SEE ALSO 🧚


and that's the whole page, bestie πŸ’– this one came from the Debian crew and she's dated September 12, 2019 β€” so when you're done reading, go read your MAT files. periodt. πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from