MAT_VARREADNEXT(3)

πŸ’– MAT_VARREADNEXT β€” the manual page, but make it make sense πŸ’–

okay bestie, so this is a page from the Library Functions Manual, and it's literally the glow-up guide to one single function. no cap. let's get into it.


✨ NAME ✨

Mat_VarReadNext β€” reads the info and the data for the next variable in a MATLAB MAT file. the whole package, bestie, not just the teaser πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <matio.h>

matvar_t *
Mat_VarReadNext(mat_t *matfp);

🌸 DESCRIPTION 🌸

so the Mat_VarReadNext() function reads the information and the data for the next variable stored in the open MAT file. that's it, that's the job. she's simple, she's focused, she's iconic πŸ‘‘


πŸ’… RETURN VALUES πŸ’…

  • if there's another variable in the MAT file and it gets read successfully, you get back a pointer to the MATLAB variable structure. slay 🫢
  • if there are no more variables, or there was an error reading the variable, you get NULL. that's the vibe check failing, ngl 😭

πŸ”₯ EXAMPLES πŸ”₯

this example program opens a MAT file named by the first argument to the program, and uses Mat_VarReadNext() to read each variable in the file. for each variable read, the Mat_VarPrint(3) function is used to display the information and data of the variable. it's giving "loop and print, loop and print, main character energy" ✨

#include <stdlib.h>
#include <stdio.h>
#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;
    }

    while ( NULL != (matvar = Mat_VarReadNext(matfp)) ) {
        Mat_VarPrint(matvar, 1);
        Mat_VarFree(matvar);
    }

    Mat_Close(matfp);
    return EXIT_SUCCESS;
}
not me noticing that fprintf line has a little typo in it (%s0 instead of %s") ...) but bestie I am NOT touching it, I copy exactly what the page says, character for character, always πŸ’€ copy-paste is sacred, periodt.

πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page, bestie!! this lil gem ships with Debian, dated September 12, 2019 β€” yeah she's a 2019 girlie and she still ate πŸ’…βœ¨ go read some MAT files, you got this πŸ¦‹πŸŒˆ

πŸ“¦ where this page comes from