#include "mat.h" Matrix *matGetNextMatrix(fp)MATFile *fp;
integer*4 function matGetNextMatrix(fp)integer*4 fp
fp
matGetNextMatrix reads the next Matrix from the MAT-file pointed to by fp and returns a pointer to a newly allocated Matrix structure. Use it immediately after opening the MAT-file with matOpen and not in conjunction with other MAT-file routines; otherwise, the concept of the next Matrix is undefined.
matGetNextMatrix returns NULL when the end-of-file is reached or if there is an error condition. Use feof and ferror from the Standard C Library to determine status.
Be careful in your code to free the Matrix created by this routine when you are finished with it.
Print out the row dimensions of all the Matrices in a MAT-file.
/*mattest3.c*/#include <string.h> #include "mat.h" main() { MATFile *fp;Matrix *mp;fp = matOpen("foo.mat","r"); while ((mp = matGetNextMatrix(fp)) != NULL) { printf("Row dimension is %d\n",mxGetM(mp)); mxFreeMatrix(mp); } matClose(fp); }
The Fortran version of this code is in mattest3.f:
program maininteger matOpen,matClose,mxGetMinteger mp, fp, stat, matGetNextMatrixcmh = matOpen('foo.mat','r')do 10 i = 1,1000mp = matGetNextMatrix(fp)if (mp .eq. 0) thengo to 20end ifwrite(6,*) 'Row dimension is ',mxGetM(mp)mxFreeMatrix(mp)10 continue20 continuestat = matClose(fp)cstopend
(c) Copyright 1994 by The MathWorks, Inc.