William Handler
07-24-2008, 02:25 PM
Hi all
I have written a few mex functions to implement some fast c code ion matlab for various electromagnetic calculations we do. No problem. I got a recent copy of NR3 with the source code so I could start to include some NR3 code in out matlab code set and I have run int the most basic problem of all. I cannot get the hello world routine to do its magic.
INFORMATION:
matlab 2007b, mac os x leopard 10.5.4
The code looks like this...
/* helloworld2.cpp */
#include "nr3matlab.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
MatDoub indata(prhs[0]);
Int i, j, k=0, m=indata.nrows(), n=indata.ncols();
VecDoub outdata(m*n,plhs[0]);
for (i=0;i<m;i++) for (j=0;j<n;j++) outdata[k++] = SQR(indata[i][j]);
printf("Hello, world!\n");
}
The math part works whenI run it from matlab, but no hello world. Also, I did have to change the nr3matlab.h file to get it to compile as it complained about the typeinfo header file. I changed that line from
#include <typeinfo.h>
to
#include <typeinfo>
BY the way, I think this is a good forum concept and I will post my wrappers and makefile for the mex functions as I get them done. That is if I ever get helloworld to work.........
I have written a few mex functions to implement some fast c code ion matlab for various electromagnetic calculations we do. No problem. I got a recent copy of NR3 with the source code so I could start to include some NR3 code in out matlab code set and I have run int the most basic problem of all. I cannot get the hello world routine to do its magic.
INFORMATION:
matlab 2007b, mac os x leopard 10.5.4
The code looks like this...
/* helloworld2.cpp */
#include "nr3matlab.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
MatDoub indata(prhs[0]);
Int i, j, k=0, m=indata.nrows(), n=indata.ncols();
VecDoub outdata(m*n,plhs[0]);
for (i=0;i<m;i++) for (j=0;j<n;j++) outdata[k++] = SQR(indata[i][j]);
printf("Hello, world!\n");
}
The math part works whenI run it from matlab, but no hello world. Also, I did have to change the nr3matlab.h file to get it to compile as it complained about the typeinfo header file. I changed that line from
#include <typeinfo.h>
to
#include <typeinfo>
BY the way, I think this is a good forum concept and I will post my wrappers and makefile for the mex functions as I get them done. That is if I ever get helloworld to work.........