<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/159393</link>
    <title>MATLAB Central Newsreader - mex variable problems</title>
    <description>Feed for thread: mex variable problems</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 15 Nov 2007 21:25:10 -0500</pubDate>
      <title>mex variable problems</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/159393#401568</link>
      <author>Steven </author>
      <description>Hi, I want to pass in data from matlab and copy it to a&lt;br&gt;
variable within c++, then do whatever with it... I have run&lt;br&gt;
into a couple problems. &lt;br&gt;
1. The documentation in matlab is terrible on this. They&lt;br&gt;
either use a mxArray throughout the program or a scalar copy&lt;br&gt;
to pass in the data. Have they considered that a majority of&lt;br&gt;
users won't want to use mxArrays ? Its easier to port your&lt;br&gt;
function if you can copy stuff over to arrays.&lt;br&gt;
2. A good way to dynamically allocate memory in c++ (I've&lt;br&gt;
forgotten how)&lt;br&gt;
3. I can't copy data from *prhs to a double array (Vec in&lt;br&gt;
this case) in matlab. I can't even display the output, the&lt;br&gt;
code below when i call it from matlab has this output:&lt;br&gt;
&lt;br&gt;
test([1 3 5 4 5])&lt;br&gt;
F1  --- 0 &lt;br&gt;
F1  --- 0 &lt;br&gt;
F1  --- 0 &lt;br&gt;
F1  --- 0 &lt;br&gt;
F1  --- 0 &lt;br&gt;
&lt;br&gt;
void mexFunction(int nlhs, mxArray *plhs[ ],int nrhs,&lt;br&gt;
xArray *prhs[ ]){&lt;br&gt;
int i,j,avg;&lt;br&gt;
mxArray *xData;&lt;br&gt;
double *xValues;&lt;br&gt;
int xrowLen, xcolLen;&lt;br&gt;
double temp;&lt;br&gt;
double Vec[];&lt;br&gt;
int ii,jj;&lt;br&gt;
&lt;br&gt;
xData = prhs[0];&lt;br&gt;
xValues = mxGetPr(xData);&lt;br&gt;
xrowLen = mxGetN(xData);&lt;br&gt;
xcolLen = mxGetM(xData);&lt;br&gt;
&lt;br&gt;
if(( xrowLen&amp;lt;1)|( xcolLen!=1)){&lt;br&gt;
	mexErrMsgTxt(&quot;WARNING: ONLY PASS IN ROW VECTOR&quot;);&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
for(i=0;i&amp;lt;xrowLen;i++)&lt;br&gt;
{&lt;br&gt;
	for(j=0;j&amp;lt;xcolLen;j++)&lt;br&gt;
	{&lt;br&gt;
		temp = xValues[i+j];&lt;br&gt;
		printf(&quot;F1  --- %d \n&quot;,temp  );&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vec[i][j] = temp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
}&lt;br&gt;
}</description>
    </item>
    <item>
      <pubDate>Thu, 15 Nov 2007 21:42:07 -0500</pubDate>
      <title>Re: mex variable problems</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/159393#401574</link>
      <author>Peter Boettcher</author>
      <description>&quot;Steven &quot; &amp;lt;burrguy.athotmailnot@msn.com&amp;gt; writes:&lt;br&gt;
&lt;br&gt;
&amp;gt; Hi, I want to pass in data from matlab and copy it to a&lt;br&gt;
&amp;gt; variable within c++, then do whatever with it... I have run&lt;br&gt;
&amp;gt; into a couple problems. &lt;br&gt;
&lt;br&gt;
&amp;gt; 1. The documentation in matlab is terrible on this. They&lt;br&gt;
&amp;gt; either use a mxArray throughout the program or a scalar copy&lt;br&gt;
&amp;gt; to pass in the data. Have they considered that a majority of&lt;br&gt;
&amp;gt; users won't want to use mxArrays ? Its easier to port your&lt;br&gt;
&amp;gt; function if you can copy stuff over to arrays.&lt;br&gt;
&lt;br&gt;
Most of us find the documentation complete.  &lt;br&gt;
&lt;br&gt;
I'm not sure what you mean that most users won't want to use mxArrays.&lt;br&gt;
The mxArray is simply the way MATLAB stores arrays, and you get access&lt;br&gt;
to it directly in your mexFunction.  The rest of your code should NOT&lt;br&gt;
use mxArrays, but should reference data based on the data pointer stored&lt;br&gt;
in mxArray.  You don't need to copy the data out.&lt;br&gt;
&lt;br&gt;
I suggest a detailed study of the examples to see the intended usage.&lt;br&gt;
&lt;br&gt;
&amp;gt; 2. A good way to dynamically allocate memory in c++ (I've&lt;br&gt;
&amp;gt; forgotten how)&lt;br&gt;
&lt;br&gt;
I would use mxMalloc, which lets MATLAB help in the cleanup process if&lt;br&gt;
something goes wrong.&lt;br&gt;
&lt;br&gt;
&amp;gt; 3. I can't copy data from *prhs to a double array (Vec in&lt;br&gt;
&amp;gt; this case) in matlab. I can't even display the output, the&lt;br&gt;
&amp;gt; code below when i call it from matlab has this output:&lt;br&gt;
&lt;br&gt;
You shouldn't have to copy the data.  You can just use xValues as your&lt;br&gt;
array.  xValues[0] is the first element, xValues[1] is the next, etc.&lt;br&gt;
&lt;br&gt;
More comments below.&lt;br&gt;
&lt;br&gt;
&amp;gt; test([1 3 5 4 5])&lt;br&gt;
&amp;gt; F1  --- 0 &lt;br&gt;
&amp;gt; F1  --- 0 &lt;br&gt;
&amp;gt; F1  --- 0 &lt;br&gt;
&amp;gt; F1  --- 0 &lt;br&gt;
&amp;gt; F1  --- 0 &lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; void mexFunction(int nlhs, mxArray *plhs[ ],int nrhs,&lt;br&gt;
&amp;gt; xArray *prhs[ ]){&lt;br&gt;
&amp;gt; int i,j,avg;&lt;br&gt;
&amp;gt; mxArray *xData;&lt;br&gt;
&amp;gt; double *xValues;&lt;br&gt;
&amp;gt; int xrowLen, xcolLen;&lt;br&gt;
&amp;gt; double temp;&lt;br&gt;
&amp;gt; double Vec[];&lt;br&gt;
&lt;br&gt;
Vec is a garbage pointer.  You can't store anything to Vec until you&lt;br&gt;
allocate memory for it.&lt;br&gt;
&lt;br&gt;
&amp;gt; int ii,jj;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; xData = prhs[0];&lt;br&gt;
&amp;gt; xValues = mxGetPr(xData);&lt;br&gt;
&amp;gt; xrowLen = mxGetN(xData);&lt;br&gt;
&amp;gt; xcolLen = mxGetM(xData);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; if(( xrowLen&amp;lt;1)|( xcolLen!=1)){&lt;br&gt;
&amp;gt; 	mexErrMsgTxt(&quot;WARNING: ONLY PASS IN ROW VECTOR&quot;);&lt;br&gt;
&amp;gt; }&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; for(i=0;i&amp;lt;xrowLen;i++)&lt;br&gt;
&amp;gt; {&lt;br&gt;
&amp;gt; 	for(j=0;j&amp;lt;xcolLen;j++)&lt;br&gt;
&amp;gt; 	{&lt;br&gt;
&amp;gt; 		temp = xValues[i+j];&lt;br&gt;
&lt;br&gt;
I know that you've limited j to be always zero, but this expression&lt;br&gt;
isn't right for a 2D access.  The 2D to 1D conversion is &lt;br&gt;
[row + column*numRows].&lt;br&gt;
&lt;br&gt;
&amp;gt; 		printf(&quot;F1  --- %d \n&quot;,temp  );&lt;br&gt;
&lt;br&gt;
Your print fails because you've told printf to expect an integer, while&lt;br&gt;
you are passing a float.  Try %f.&lt;br&gt;
&lt;br&gt;
&amp;gt;                 Vec[i][j] = temp;&lt;br&gt;
&lt;br&gt;
As already mentioned, this is invalid since you've not allocated memory&lt;br&gt;
for Vec.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
-Peter</description>
    </item>
    <item>
      <pubDate>Fri, 16 Nov 2007 08:57:08 -0500</pubDate>
      <title>Re: mex variable problems</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/159393#401640</link>
      <author>James Tursa</author>
      <description>&lt;br&gt;
Here are some comments (Peter has already mentioned some of these&lt;br&gt;
which I will repeat)&lt;br&gt;
&lt;br&gt;
&amp;gt;1. The documentation in matlab is terrible on this. They&lt;br&gt;
&amp;gt;either use a mxArray throughout the program or a scalar copy&lt;br&gt;
&amp;gt;to pass in the data. Have they considered that a majority of&lt;br&gt;
&amp;gt;users won't want to use mxArrays ? Its easier to port your&lt;br&gt;
&amp;gt;function if you can copy stuff over to arrays.&lt;br&gt;
&lt;br&gt;
Well, MATLAB stores data differently than C or C++, Fortran stores&lt;br&gt;
data differently than C or C++, etc. etc. It should be expected that&lt;br&gt;
any other language may store data differently than C or C++. It is not&lt;br&gt;
fair to complain that you have to do something extra to get the data&lt;br&gt;
from another language into yours. Since MATLAB has dynamic typing,&lt;br&gt;
there is bound to be some overhead for their variables to take care of&lt;br&gt;
this. Why should one be surprised at this?  MATLAB has kindly provided&lt;br&gt;
functions to extract the data into your C or C++ variables. Most of us&lt;br&gt;
love MATLAB and are willing to live with this. As an analogy, how&lt;br&gt;
would you get or manipulate data from a C++ class? Member functions,&lt;br&gt;
right? What's the big deal about calling functions to get data from&lt;br&gt;
the MATLAB mxArrays when this is what you do all the time for C++&lt;br&gt;
classes to get at the data?&lt;br&gt;
&lt;br&gt;
&amp;gt;2. A good way to dynamically allocate memory in c++ (I've&lt;br&gt;
&amp;gt;forgotten how)&lt;br&gt;
&lt;br&gt;
You might review &quot;new&quot;. But as Peter mentioned, if you use mxMalloc&lt;br&gt;
and mxCalloc you give the MATLAB memory manager a chance to clean up&lt;br&gt;
all of your memory if something goes wrong.&lt;br&gt;
&lt;br&gt;
&amp;gt;3. I can't copy data from *prhs to a double array (Vec in&lt;br&gt;
&amp;gt;this case) in matlab. I can't even display the output, the&lt;br&gt;
&amp;gt;code below when i call it from matlab has this output:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;test([1 3 5 4 5])&lt;br&gt;
&amp;gt;F1  --- 0 &lt;br&gt;
&amp;gt;F1  --- 0 &lt;br&gt;
&amp;gt;F1  --- 0 &lt;br&gt;
&amp;gt;F1  --- 0 &lt;br&gt;
&amp;gt;F1  --- 0 &lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;void mexFunction(int nlhs, mxArray *plhs[ ],int nrhs,&lt;br&gt;
&amp;gt;xArray *prhs[ ]){&lt;br&gt;
&amp;gt;int i,j,avg;&lt;br&gt;
&amp;gt;mxArray *xData;&lt;br&gt;
&amp;gt;double *xValues;&lt;br&gt;
&amp;gt;int xrowLen, xcolLen;&lt;br&gt;
&amp;gt;double temp;&lt;br&gt;
&amp;gt;double Vec[];&lt;br&gt;
&amp;gt;int ii,jj;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;xData = prhs[0];&lt;br&gt;
&amp;gt;xValues = mxGetPr(xData);&lt;br&gt;
&amp;gt;xrowLen = mxGetN(xData);&lt;br&gt;
&amp;gt;xcolLen = mxGetM(xData);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;if(( xrowLen&amp;lt;1)|( xcolLen!=1)){&lt;br&gt;
&amp;gt;	mexErrMsgTxt(&quot;WARNING: ONLY PASS IN ROW VECTOR&quot;);&lt;br&gt;
&amp;gt;}&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;for(i=0;i&amp;lt;xrowLen;i++)&lt;br&gt;
&amp;gt;{&lt;br&gt;
&amp;gt;	for(j=0;j&amp;lt;xcolLen;j++)&lt;br&gt;
&amp;gt;	{&lt;br&gt;
&amp;gt;		temp = xValues[i+j];&lt;br&gt;
&amp;gt;		printf(&quot;F1  --- %d \n&quot;,temp  );&lt;br&gt;
&amp;gt;                Vec[i][j] = temp;&lt;br&gt;
&amp;gt;    }&lt;br&gt;
&amp;gt;}&lt;br&gt;
&amp;gt;}&lt;br&gt;
&lt;br&gt;
Many specific comments about your code:&lt;br&gt;
&lt;br&gt;
1) You are missing the #include &quot;mex.h&quot; line. You should include this&lt;br&gt;
to make sure you get all the types defined, etc.&lt;br&gt;
&lt;br&gt;
2) You misspelled mxArray as xArray in the argument list, and you did&lt;br&gt;
not include the const attribute for prhs[].&lt;br&gt;
&lt;br&gt;
3) This line is not the correct way to define an array:&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; double Vec[];&lt;br&gt;
&lt;br&gt;
When you declare an array like this the compiler needs to know what&lt;br&gt;
size it is, you can't leave the size blank. It appears that you would&lt;br&gt;
like to declare Vec in such a way that you can later on use the&lt;br&gt;
Vec[i][j] notation in your code for dereferencing a Vec element. You&lt;br&gt;
can't do this in general. The compiler needs to know at compile time&lt;br&gt;
exactly what type of pointer Vec is, meaning the compiler needs to&lt;br&gt;
know the size and type of things that Vec points to at compile time.&lt;br&gt;
You can't declare Vec at compile time to be an arbitrary sized array.&lt;br&gt;
The most you can get away with is declaring a pointer to an array of a&lt;br&gt;
fixed size and then allocate memory for it at run time, for instance:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;double (*Vec)[5];&lt;br&gt;
&lt;br&gt;
This declares Vec to be a pointer to an array of doubles of length 5&lt;br&gt;
(but does not allocate any memory for such an array). Then later on in&lt;br&gt;
your code you could allocate memory for Vec and use the Vec[i][j]&lt;br&gt;
notation and it would work correctly. But this *only* works because&lt;br&gt;
the compiler knows at compile time exactly what Vec points to. You&lt;br&gt;
could not do this:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;double (*Vec)[m];&lt;br&gt;
&lt;br&gt;
where m was a variable defined at run time, because the size of things&lt;br&gt;
that Vec points to is not known at compile time. So you are going to&lt;br&gt;
have to live with doing the dereferencing arithmetic yourself as Peter&lt;br&gt;
mentioned.&lt;br&gt;
&lt;br&gt;
You could declare Vec as a simple pointer to double:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;double *Vec;&lt;br&gt;
&lt;br&gt;
and then use a macro to mimic the Vec[i][j] dereferencing (assuming&lt;br&gt;
that the data was copied correctly into the memory that Vec points&lt;br&gt;
to):&lt;br&gt;
&lt;br&gt;
#define VEC(i,j) Vec[j+(i)*N]&lt;br&gt;
&lt;br&gt;
But this is about as close as you will get to the actual Vec[i][j]&lt;br&gt;
notation for a dynamically allocated size 2-dimensional matrix.&lt;br&gt;
&lt;br&gt;
If Vec is pointing directly at a mxArray data location like this:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vec = (double *) mxGetPr(prhs[0]);&lt;br&gt;
&lt;br&gt;
Then you can simply reverse the indexing scheme of the macro to take&lt;br&gt;
care of it in your C code (since MATLAB stores data column wise):&lt;br&gt;
&lt;br&gt;
#define VEC(i,j) Vec[i+(j)*M]&lt;br&gt;
&lt;br&gt;
3) You don't do any error checking of the inputs. The user might not&lt;br&gt;
be giving this function what it expects, so the inputs should always&lt;br&gt;
be checked. For example, your very first executable line xData =&lt;br&gt;
prhs[0] will have a problem if the user calls the function with no&lt;br&gt;
input arguments since prhs[0] will be invalid in this case.&lt;br&gt;
&lt;br&gt;
4) The following lines are a bit confusing to me. Normally N is the&lt;br&gt;
column and M is the row, but your are reversing that naming convention&lt;br&gt;
with these lines. Not at all sure if this is intentional.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xrowLen = mxGetN(prhs[0]);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xcolLen = mxGetM(prhs[0]);&lt;br&gt;
&lt;br&gt;
5) Why are you using the bit-wise or operator | in the following line?&lt;br&gt;
It seems to clearly be a logical operation you are doing, not a&lt;br&gt;
bit-wise operation. Admittedly you will wind up with the same logical&lt;br&gt;
result in this particular case, but use of the | operator here instead&lt;br&gt;
of || just doesn't look like good programming.&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt;   if(( xrowLen&amp;lt;1)|( xcolLen!=1)){&lt;br&gt;
&lt;br&gt;
6) The dereferencing line temp = xValues[i+j], as Peter pointed out,&lt;br&gt;
is not correct for an arbitrary size 2-dimensional dereferencing. It&lt;br&gt;
only happens to work logically in your case because one of the&lt;br&gt;
dimensions is 1 (which begs the question why is there a double loop&lt;br&gt;
construct used here when one of them only loops on one value?).&lt;br&gt;
&lt;br&gt;
7) You are using the incorrect format, %d, to print a double. You&lt;br&gt;
should use %f. Also, use mexPrintf instead of printf.&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt;   printf(&quot;F1  --- %d \n&quot;,temp  );&lt;br&gt;
&lt;br&gt;
8) The use of more spacing would make your code much more readable.&lt;br&gt;
&lt;br&gt;
I have included a working mex file below based on your example. I made&lt;br&gt;
some assumptions about what you were actually after. Note that if you&lt;br&gt;
comment out the following lines the mex function will work just fine&lt;br&gt;
for any sized 2-dimensional array, not just row vectors.&lt;br&gt;
&lt;br&gt;
//    if( ( n &amp;lt; 1 ) || ( m != 1 ) ){&lt;br&gt;
//        mexErrMsgTxt(&quot;WARNING: ONLY PASS IN ROW VECTOR&quot;);&lt;br&gt;
//    }&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
James Tursa&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
#include &quot;mex.h&quot;&lt;br&gt;
&amp;nbsp;&lt;br&gt;
#define VEC(i,j) Vec[j+(i)*n]&lt;br&gt;
#define XVALUES(i,j) xValues[i+(j)*m]&lt;br&gt;
&amp;nbsp;&lt;br&gt;
void mexFunction(int nlhs, mxArray *plhs[],int nrhs,&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;const mxArray *prhs[])&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int i, j;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;double *xValues;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int m, n;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;double *Vec;&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (nrhs != 1)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mexErrMsgTxt(&quot;One input arguments required.&quot;);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (nlhs &amp;gt; 0)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mexErrMsgTxt(&quot;Too many output arguments.&quot;);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if( !mxIsDouble(prhs[0]) )&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mexErrMsgTxt(&quot;Argument need to be double.&quot;);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if( mxIsEmpty(prhs[0]) )&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mexErrMsgTxt(&quot;Argument cannot be empty.&quot;);&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xValues = mxGetPr(prhs[0]);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;m = mxGetM(prhs[0]);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;n = mxGetN(prhs[0]);&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if( ( n &amp;lt; 1 ) || ( m != 1 ) ){&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mexErrMsgTxt(&quot;WARNING: ONLY PASS IN ROW VECTOR&quot;);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vec = (double *) mxCalloc(n*m, sizeof(double));&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for( i=0; i&amp;lt;m; i++ )&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for( j=0; j&amp;lt;n; j++ )&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;VEC(i,j) = XVALUES(i,j);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mexPrintf(&quot;VEC(%d,%d) = %f \n&quot;, i, j, VEC(i,j));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mxFree(Vec);&lt;br&gt;
}</description>
    </item>
  </channel>
</rss>

