MATLAB REAL-TIME WORKSHOP 7 - TARGET LANGUAGE COMPILER Manuel d'utilisateur Page 127

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 408
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 126
Examples of Fortran MEX-Files
3-17
Passing Matrices
In MATLAB, you can pass matrices into and out of MEX-files written in
Fortran. You can manipulate the MATLAB arrays by using
mxGetPr and
mxGetPi to assign pointers to the real and imaginary parts of the data stored
in the MATLAB arrays. You can create new MATLAB arrays from within your
MEX-file by using
mxCreateFull.
This example takes a real 2-by-3 matrix and squares each element.
C--------------------------------------------------------------
C
C matsq.f
C
C Squares the input matrix
C This is a MEX-file for MATLAB.
C Copyright (c) 1984-2000 The MathWorks, Inc.
C $Revision: 1.12 $
C--------------------------------------------------------------
subroutine matsq(y, x, m, n)
real*8 x(m,n), y(m,n)
integer m, n
C
do 20 i=1,m
do 10 j=1,n
y(i,j)= x(i,j)**2
10 continue
20 continue
return
end
This is the gateway routine that calls the computational subroutine.
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
C--------------------------------------------------------------
C (pointer) Replace integer by integer*8 on the DEC Alpha
C platform.
C
integer plhs(*), prhs(*)
integer mxCreateFull, mxGetPr
Vue de la page 126
1 2 ... 122 123 124 125 126 127 128 129 130 131 132 ... 407 408

Commentaires sur ces manuels

Pas de commentaire