C This is an adaptation of matsq from the API Guide. C C This file has been written to demonstrate the use C of two functions so that the size of the input C matrices must not be known at compilation. C C As an m-file, this would be written C function z=multscalar(x,y) C % x is a matrix of any dimension C % y is a scalar C z=x*y; C C Written by Matthew C Roberts, matthewcroberts@hotmail.com C C This is the gateway function subroutine mexFunction(nlhs,plhs,nrhs,prhs) implicit none integer nlhs, nrhs, mxGetM, mxGetN integer m(nrhs), n(nrhs), mxIsNumeric C Change this to integer*8 for 64 bit matchines integer plhs(nlhs), prhs(nrhs) C Check the proper number of input and output arguments if (nlhs .gt. 1) then call mexErrMsgTxt('No more than one output argument') end if if (nrhs .ne. 2) then call mexErrMsgTxt('Must be exactly two input arguments') end if C Check to make sure that the arguments are non-numeric if (mxIsNumeric(prhs(1)).eq.0) then call mexErrMsgTxt('Non-numeric Data Present') end if if (mxIsNumeric(prhs(2)).eq.0) then call mexErrMsgTxt('Non-numeric Data Present') end if C Get size of input arguments m(1)=mxGetM(prhs(1)) m(2)=mxGetM(prhs(2)) n(1)=mxGetN(prhs(1)) n(2)=mxGetN(prhs(2)) call matmult_1(nlhs,plhs,nrhs,prhs,m,n) end C ================================================================= C This is the computational function subroutine matmult_1(nlhs,plhs,nrhs,prhs,m,n) implicit none integer nrhs, nlhs integer m(nrhs), n(nrhs) C These are the input argument double precision x(m(1),n(1)), y, z(m(1),n(1)) C Change these to integer*8 for 64 bit machines integer plhs(nlhs), prhs(nrhs), zpr integer mxCreateFull, mxGetPr external mxGetPr C Copy the inputs into FORTRAN call mxCopyPtrtoReal8(mxGetPr(prhs(1)),x,m(1)*n(1)) call mxCopyPtrtoReal8(mxGetPr(prhs(2)),y,1) C Now, do the math: call matmult_2(x,y,z,m,n) C Send the answer home plhs(1)=mxCreateFull(m(1),n(1),0) zpr=mxGetPr(plhs(1)) call mxCopyReal8toPtr(z,zpr,m(1)*n(1)) end C Computational Subroutine? subroutine matmult_2(x,y,z,m,n) implicit none integer m(2), n(2) double precision x(m(1),n(1)), y, z(m(1),n(1)) z = x*y end