MAT_REWIND(3)
π MAT_REWIND(3) π
okay bestie, welcome to the Library Functions Manual β this is the MAT_REWIND page and it's honestly such a tiny little icon, one job, does it perfectly. β¨
πΈ NAME πΈ
Mat_Rewind β rewinds an open MAT file all the way back to the beginning. that's it. that's the whole gig. π
π SYNOPSIS π
#include <matio.h>
int
Mat_Rewind(mat_t *matfp);
π¦ DESCRIPTION π¦
so like. you've got an open MAT file, right? and you've been reading through it, vibing, consuming variables one by one. and now you wanna go back to the start. not me rewinding the whole thing like a cassette tape π§
Mat_Rewind rewinds an open MAT file so that Mat_VarReadNext() or Mat_VarReadNextInfo() reads the first variable in the file. that's the entire plot. main character energy, minimal runtime, zero filler. π
β¨ RETURN VALUES β¨
0β success, we ate, the file is rewound, slay π-1β failure π something went sideways, no rewind for you
π EXAMPLES π
ok so here's the cutest little program. it lists out all the variables in the MAT file, asks you which one you want, and if your index is actually valid it resets the file to the beginning and reads forward until it hits your chosen index. lowkey elegant ngl π«Ά
#include <stdlib.h>
#include <stdio.h>
#include "matio.h"
int
main(int argc, char **argv)
{
mat_t *matfp;
matvar_t *matvar;
int idx, num_variables;
matfp = Mat_Open(argv[1], MAT_ACC_RDONLY);
if ( NULL == matfp ) {
fprintf(stderr, "Error opening MAT file %s0, argv[1]);
return EXIT_FAILURE;
}
idx = 0;
while ( NULL != (matvar = Mat_VarReadNextInfo(matfp)) ) {
idx++;
printf("%3d. %s0, idx, matvar->name);
Mat_VarFree(matvar);
}
num_variables = idx;
if ( num_variables > 0 ) {
printf("Which variable would you like to read? ");
if ( 0 == fscanf(stdin,"%d",&idx) ) {
printf("Invalid variable selection!0);
} else if ( idx < 1 || idx > num_variables ) {
fprintf(stderr, "That is an invalid variable index!0);
} else {
int k;
Mat_Rewind(matfp);
for ( k = 1; k < idx; k++ ) {
matvar = Mat_VarReadNextInfo(matfp);
Mat_VarFree(matvar);
}
matvar = Mat_VarReadNext(matfp);
Mat_VarPrint(matvar, 1);
Mat_VarFree(matvar);
}
}
Mat_Close(matfp);
return EXIT_SUCCESS;
}
see the moment? right there in the middle β Mat_Rewind(matfp); β file goes whoosh back to the top and then we count forward to the one you asked for. iconic behaviour, truly. π
π₯ SEE ALSO π₯
and that's the whole page bestie!! this little drop of sunshine came from Debian, dated September 12, 2019. go forth and rewind responsibly ππ§β¨
π¦ 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) 2011-2014, Christopher C. Hulbert
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms