Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: mex variable problems
Date: Thu, 15 Nov 2007 21:25:10 +0000 (UTC)
Organization: Dixie State College of Utah
Lines: 52
Message-ID: <fhidfm$mlo$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1195161910 23224 172.30.248.38 (15 Nov 2007 21:25:10 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 15 Nov 2007 21:25:10 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 785751
Xref: news.mathworks.com comp.soft-sys.matlab:437807



Hi, I want to pass in data from matlab and copy it to a
variable within c++, then do whatever with it... I have run
into a couple problems. 
1. The documentation in matlab is terrible on this. They
either use a mxArray throughout the program or a scalar copy
to pass in the data. Have they considered that a majority of
users won't want to use mxArrays ? Its easier to port your
function if you can copy stuff over to arrays.
2. A good way to dynamically allocate memory in c++ (I've
forgotten how)
3. I can't copy data from *prhs to a double array (Vec in
this case) in matlab. I can't even display the output, the
code below when i call it from matlab has this output:

test([1 3 5 4 5])
F1  --- 0 
F1  --- 0 
F1  --- 0 
F1  --- 0 
F1  --- 0 

void mexFunction(int nlhs, mxArray *plhs[ ],int nrhs,
xArray *prhs[ ]){
int i,j,avg;
mxArray *xData;
double *xValues;
int xrowLen, xcolLen;
double temp;
double Vec[];
int ii,jj;

xData = prhs[0];
xValues = mxGetPr(xData);
xrowLen = mxGetN(xData);
xcolLen = mxGetM(xData);

if(( xrowLen<1)|( xcolLen!=1)){
	mexErrMsgTxt("WARNING: ONLY PASS IN ROW VECTOR");
}


for(i=0;i<xrowLen;i++)
{
	for(j=0;j<xcolLen;j++)
	{
		temp = xValues[i+j];
		printf("F1  --- %d \n",temp  );
                Vec[i][j] = temp;
    }
}
}