home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / SRC.DI$ / MATTEST2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-26  |  593 b   |  32 lines

  1. /*
  2.  *    MATTEST2
  3.  *
  4.  *    Simple program that illustrates how to call the MAT-file Library
  5.  *    from a C program.  
  6.  *
  7.  *    The example reads a matrix into a double array.
  8.  *    The matrix is named, "A", and the MAT-file is named, "foo.mat".
  9.  *    
  10.  */
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include "mat.h"
  14.  
  15. static double Areal[6];
  16.  
  17. main()
  18. {
  19.     MATFile *fp;
  20.     Matrix *a;
  21.     int mn;
  22.  
  23.     fp = matOpen("foo.mat", "r");
  24.     a = matGetMatrix(fp, "A");
  25.     mn = mxGetM(a) * mxGetN(a);
  26.     memcpy(Areal, mxGetPr(a), mn*sizeof(double));
  27.     matClose(fp);
  28.     mxFreeMatrix(a);
  29.     printf("\nRow 1: %g %g\n",Areal[0],Areal[3]);
  30.     exit(0);
  31. }
  32.