MATLAB COMPILER 4 Manuale Utente Pagina 15

  • Scaricare
  • Aggiungi ai miei manuali
  • Stampa
  • Pagina
    / 21
  • Indice
  • SEGNALIBRI
  • Valutato. / 5. Basato su recensioni clienti
Vedere la pagina 14
fun cti on [C , D ] = simple (A , B , T e stStr )
f p r i n t f ([ TestStr , \ n\ n ]);
C = A + B ;
D = A * B ;
return ;
Listing 3: simple.m
This is a Test String .
Output by C API In t erface Function
5
6
Output by C Native Function
2.000000 3.000000
5.000000 6.000000
Listing 4: Output of the Test Program
5.2.1 Additional Explanation for the Example Source Code
line 1: The include file matlab.h provides the interfaces for the MATLAB C Interface API.
line 2: The include file libsimple.h is created by the mcc compiler and must be include d
in the beginning of the C-source code.
line 11: The data interface between any MATLAB functions and the C-source Code is
defined by a pointer to the data type mxArray (for more details see: [6]).
line 24: A more general way to convert double values to mxArrays, is to use a
mxCreateDoubleMatrix (see: line 20) and then make a memcpy operation. This
would be valid for all arrays:
memcpy(mxGetP r(pmxDoubleVar), &DoubleVar, nsizeof(double));
line 28: When working with MATLAB-functions the equal operator should be replaced by
the function mlfAssign. This ensures a robust memory management. mlfAssign
returns a pointer to the target array.
line 29: If a function has more than one output parameter, these parameters are passed to
the function as the first input parameter of the type **mxArray. All other input
parameters are of the type *mxArray.
Some other examples for mixing M-files and C-code can be find in [4]. For a complete list
of MATALB C/C++ API Functions with detailed short examples refer to [5, 7].
15
Vedere la pagina 14
1 2 ... 10 11 12 13 14 15 16 17 18 19 20 21

Commenti su questo manuale

Nessun commento