MATLAB Application Program Interface Reference | Help Desk |
matGetNextMatrix
Get nextmxArray
from MAT-file
integer*4 function matGetNextMatrix(mfp) integer*4 mfp
mfp
Pointer to MAT-file information.
This routine allows you to step sequentially through a MAT-file and read all themxArrays
in a single pass.
matGetNextMatrix
reads the next mxArray
from the MAT-file pointed to by mfp
and returns a pointer to a newly allocated mxArray
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 mxArray
is undefined.
matGetNextMatrix
returns 0 when the end-of-file is reached or if there is an error condition.
Be careful in your code to free the mxArray
created by this routine when you are finished with it.
Print out the row dimensions of all the mxArrays in a MAT-file.
program main integer matOpen,matClose,mxGetM integer mp, mfp, stat, matGetNextMatrix c mh = matOpen('foo.mat','r') do 10 i = 1,1000 mp = matGetNextMatrix(mfp) if (mp .eq. 0) then go to 20 end if write(6,*) 'Row dimension is ',mxGetM(mp) mxFreeMatrix(mp) 10 continue 20 continue stat = matClose(mfp) c stop endSee
matdemo2.f
in the eng_mat
subdirectory of the examples
directory for another sample program that illustrates how to use this MAT-file routine in a Fortran program.
Note: Fortran MAT-file routines are not available on Windows.