
1 #in c lu d e " matlab .h "
2 #in c lu d e " l ibsimple .h "
3
4 i n t main ( i n t argc , char * argv [])
5 {
6 /* define variable s */
7 double A = 2; double B = 3;
8 double C = 0; double D = 0;
9 char Head [] = "This is a Test String . ";
10
11 mxArray * pmxA , * pmxB , * pmxC , * pmxD , * pmxHead ;
12
13 /* enable automate d memory man a gement */
14 ml fEnt erNe w Con t ext (0 , 0);
15
16 /* initializ e MatLab en v ironment */
17 l i bsim pleI niti aliz e ();
18
19 /* ini t ialize mxArrays */
20 pmxC = mxC reat eDou bleM atri x (1 ,1 , mxREAL );
21 pmxD = mxC reat eDou bleM atri x (1 ,1 , mxREAL );
22
23 /* copy C double value to MatLab interfac e array */
24 pmxA = mlfScalar ( A );
25 pmxB = mlfScalar ( B );
26
27 /* assign values to mxArrays */
28 mlfAssign (& pmxHead , mxC r eateS tring ( Head ));
29 mlfAssign (& pmxC , mlfSimp l e (& pmxD , pmxA , pmxB , pmxHead ));
30
31 /* read data form MatLab interface arrays back to C var i a bles */
32 C = mxGe t Scalar ( pmxC );
33 D = mxGe t Scalar ( pmxD );
34
35 /* print values */
36 printf ( " Output by C API Interf a c e Function \n " );
37 ml f Print Matri x ( pmxC );
38 ml f Print Matri x ( pmxD );
39
40 printf ( " Output by C Native Fun c t i o n \ n" );
41 printf ( "% f % f\ n% f %f\ n" , A , B , C , D );
42
43 /* free memory of MatLab interfac e arrays */
44 mx D estro yArra y ( pmxA ); mx Destr o yArra y ( pmxB );
45 mx D estro yArra y ( pmxC ); mx Destr o yArra y ( pmxD );
46
47 /* terminate the MatLab envi ronment */
48 li bsim pleT e rmi n ate ();
49
50 /* disab l e automated memory manageme n t */
51 m l fRe sto r ePr evi ous C ont ext (0 , 0);
52
53 return 0;
54 }
Listing 2: main.c
14
Komentarze do niniejszej Instrukcji