Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Using mexGetVariablePtr and mexGetVariable
Date: Sat, 14 Jun 2008 18:32:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 45
Message-ID: <g312r1$sdq$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1213468321 29114 172.30.248.35 (14 Jun 2008 18:32:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 14 Jun 2008 18:32:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1140690
Xref: news.mathworks.com comp.soft-sys.matlab:473793



hello, I have some very simple code to get a variable from
the matlab workspace into my mex function via
mexGetVariablePtr. Problem is that it seems to be getting a
0 all the time even though the workspace value (hullo=5 in
the matlab workspace) is not zero. To debug it I'm
printf-ing the initial value returned from
mexGetVariablePtr, and the numbers I'm deriving from that in
trying to get the 'hullo' value.

When I delete the hullo variable fromthe matlab workspace
and run the mex file matlab has a 'segmentation violation
detection'. This also happens if I change the variable name
from 'hullo' in my mex file to a nonexisting variable name.
-So- it seems as if the mex file is getting something
related to the 'hullo' variable, but I can't get it's actual
value,... here are some exampled printf results from when
I've run the program (hullo=5 in matlab):
myarray  658681640  | alpha  20379184  |  ho1  0
myarray  658690856  | alpha  20379264  |  ho1  0
myarray  658601072  | alpha  20361152  |  ho1  0


here's the code:



#include "mex.h"

void mexFunction(int nlhs, mxArray *plhs,
int nrhs, mxArray *prhs[])
{
int ThreadNr;
double *alpha;
double ho1;
const mxArray *myarray;

myarray = mexGetVariablePtr("base", "hullo");	//can be base
caller or global

alpha = mxGetPr(myarray);
ho1 = *alpha;

mexPrintf("myarray  %d  | alpha  %d  |  ho1  %d", myarray,
alpha, ho1);
}