MATLAB Application Program Interface Reference | Help Desk |
matGetMatrix
ReadsmxArrays
from MAT-files
integer*4 function matGetMatrix(mfp, name) integer*4 mfp character*(*) name
mfp
Pointer to MAT-file information.
name
Name of mxArray
to get from MAT-file.
mxArray
out of a MAT-file.
matGetMatrix
reads the named mxArray
from the MAT-file pointed to by mfp
and returns a pointer to a newly allocated mxArray
structure, or 0 if the attempt fails.
Be careful in your code to free the mxArray
created by this routine when you are finished with it.
Write a simple 3-by-2 real mxArray
into a MAT-file. Name the mxArray
A
and the MAT-file foo.mat
.
program main integer matOpen, mxCreateFull, matClose integer mxGetPr, matPutMatrix integer a, mfp, stat double precision Areal(6) data Areal / 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 / c mfp = matOpen('foo.mat','w') a = mxCreateFull(3, 2, 0) call mxCopyReal8ToPtr(Areal, mxGetPr(a), 6) call mxSetName(a,'A') stat = matPutMatrix(mfp,a) stat = matClose(mfp) call mxFreeMatrix(a) c stop endTo test, run this program; then go to MATLAB and enter:
load foo A A = 1 4 2 5 3 6See
matdemo1.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.