#include "matfile.h" int matGetFull(fp,name,m,n,pr,pi) MATFile *fp;
char *name;
int *m;
int *n;
double **pr;
double **pi;
int matPutFull(fp,name,m,n,pr,pi) MATFile *fp;
char *name;
int m; int n; double *pr;
double *pi;
integer*4 function matGetFull(fp,name,m,n,pr,pi)
integer*4 function matPutFull(fp,name,m,n,pr,pi)
integer*4 fp,m,n,pr,pi
character*(
*) name
fp
m
n
name
pi
pr
matGetMatrix
and matPutMatrix
, which do not require use of the Matrix structure.
matGetFull
reads the named Matrix from the MAT-file pointed to by fp
and places the row dimensions, column dimensions, real array pointer, and imaginary array pointer into the locations specified by m
, n
, pr
, and pi
, respectively.
matGetFull
returns 0 if successful, and 1 if the named variable can't be found, the named variable is not a full Matrix, or there is a file read error.
matGetFull
allocates memory for the real and imaginary arrays using mxCalloc
; use mxFree
to return the memory when you are done.
If the Matrix is pure real, the imaginary pointer is NULL
.
matPutFull
writes the Matrix with dimensions m
-by-n
, real data pr
, and imaginary data pi
onto the MAT-file fp
with the specified name
.
If the Matrix does not exist on the MAT-file, it is appended to the end. If a Matrix with the same name already exists in the file, the existing Matrix is replaced with the new Matrix by rewriting the file.
A
from one MAT-file and write it out to another:
/*The Fortran code for this example is inmattest4.c
*/
#include "mat.h" main() { MATFile *fp1,
*fp2;
int m, n double *pr,
*pi;
fp1 = matOpen("foo.mat","r"); fp2 = matOpen("foo2.mat","w"); matGetFull(fp1,"A",&m,&n,&pr,&pi); matPutFull(fp2,"A",m,n,pr,pi); matClose(fp1); matClose(fp2); }
mattest4.f
:
program main integer matOpen,matClose,matPutFull,matGetFull integer mf1, mf2, stat integer m, n, pr, pi mf1 = matOpen('foo.mat','r') mf2 = matOpen('foo2.mat','w') stat = matGetFull(mf1,'A',m,n,pr,pi) stat = matPutFull(mf2,'A',m,n,pr,pi) stat = matClose(mf1) stat = matClose(mf2) c stop endWrite a simple real Matrix into a MAT-file. Name the Matrix
A
and the MAT-file foo.mat
:
/*To test, first runmattest5.c
*/
#include "mat.h" static double Areal[6] = {1,2,3,4,5,6}; main() { MATFile *fp;
fp = matOpen("foo.mat","w"); matPutFull(fp,"A",3,2,Areal,NULL); matClose(fp); }
mattest5
; then go to MATLAB and enter:
The Fortran code for this example is inload foo
A
A =
1 4
2 5
3 6
mattest5.f
:
integer matOpen, matClose, matPutFull integer fp, stat double precision Areal(6) data Areal / 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 / c fp = matOpen('foo.mat','w') stat = matPutFull(fp,'A',3,2,Areal,0) stat = matClose(fp) c stop end
(c) Copyright 1994 by The MathWorks, Inc.