MATLAB Application Program Interface Reference | Help Desk |
matGetDir
Get directory ofmxArrays
in a MAT-file
integer*4 function matGetDir(mfp, num) integer*4 mfp, num
mfp
Pointer to MAT-file information.
num
Address of the variable to contain the number of mxArrays in the MAT-file.
This routine allows you to get a list of the names of themxArrays
contained within a MAT-file.
matGetDir
returns a pointer to an internal array containing pointers to the names of the mxArrays
in the MAT-file pointed to by mfp
. The length of the internal array (number of mxArrays
in the MAT-file) is placed into num
. The internal array is allocated using a single mxCalloc
and must be freed using mxFree
when you are finished with it.
matGetDir
returns 0 and sets num
to a negative number if it fails. If num
is zero, mfp
contains no mxArrays
.
MATLAB variable names can be up to length 32.
Print out a directory of the mxArray
names contained within a MAT-file.
program main integer*4 mfp, dir, ndir, adir(100) character*20 names(100) mfp = matOpen('foo.mat','r'); dir = matGetDir(mfp,ndir) if (dir .eq. 0) then write (6,*) 'Can't read directory.' stop end if c Copy pointer into an array of pointers call mxCopyPtrToInteger4(dir, adir, ndir) c Copy pointer to character array do 20 i = 1,ndir call mxCopyPtrToCharacter(adir(i),names(i),20) 20 continue write(6,*) 'Directory of MAT-file:' do 30 i = 1,ndir write(6,*) names(i) 30 continue matClose(mfp) 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.