Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Using mexGetVariablePtr and mexGetVariable
Date: Sat, 14 Jun 2008 19:58:01 +0000 (UTC)
Organization: Erasmusmc
Lines: 27
Message-ID: <g317s9$3sm$1@fred.mathworks.com>
References: <g312r1$sdq$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 1213473481 3990 172.30.248.38 (14 Jun 2008 19:58:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 14 Jun 2008 19:58:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1095751
Xref: news.mathworks.com comp.soft-sys.matlab:473805



> 
> #include "mex.h"
> 
> void mexFunction(int nlhs, mxArray *plhs,
> int nrhs, mxArray *prhs[])
First of all, which Matlab version are you using? The
correct function call is:

void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const
mxArray* prhs[])

(at least, for a number of versions).
> mexPrintf("myarray  %d  | alpha  %d  |  ho1  %d", myarray,
> alpha, ho1);

The bug is here. The variable is recorded correctly, but it
is a double, while printed as a integer. Use %f instead.

Btw: to prevent your code from crashing, check if
myarray!=0, e.g.:

if (myarray==NULL)
  mexErrMsgTxt("Variable hullo not initialized\n")

Greetings,
Sebastiaan