B
B.Schmidt
Hi everyone!
I have a stupid problem which apparently I cannot solve alone. I want
export some computations I do in Matlab to C.
The C code below shall write the data of a Matlab matrix into a
vector. Therefore I use two nested for-loops.
//---------------------------------------------------------------------------------------------------------------------
// beispiel.cpp
//---------------------------------------------------------------------------------------------------------------------
#include <mex.h>
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray
*prhs[] ) {
int n = mxGetN(prhs[0]);
int m = mxGetM(prhs[0]);
int u = 0;
double* punc_pat_mat = mxGetPr(prhs[0]);
plhs[0] = mxCreateDoubleMatrix(1, n*m , mxREAL);
double* punc_pat_row = mxGetPr(plhs[0]);
mexPrintf("%d Spalten\n", n);
mexPrintf("%d Zeilen\n", m);
for (int ii = 0 ; ii<(n-1) ; ii++ )
{ // line 14
for (int i = 0 ; i<(m-1) ; i
+ ) // line 15
{
punc_pat_row = punc_pat_mat[ii+i*n];
u++;
}
}
}
---------------------------------------------------------------------------------------
It is supposed to work but there is a syntax error concerning the two
for loops. Here is the compiler output:
beispiel.cpp(15) : error C2059: syntax error : ')'
beispiel.cpp(16) : error C2143: syntax error : missing ';' before '{'
I tried a lot but every change doesn't make it better and looks
stupid! What do I wrong? I would be very grateful for your help.
Thanks in advance.
regards, Bernhard
I have a stupid problem which apparently I cannot solve alone. I want
export some computations I do in Matlab to C.
The C code below shall write the data of a Matlab matrix into a
vector. Therefore I use two nested for-loops.
//---------------------------------------------------------------------------------------------------------------------
// beispiel.cpp
//---------------------------------------------------------------------------------------------------------------------
#include <mex.h>
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray
*prhs[] ) {
int n = mxGetN(prhs[0]);
int m = mxGetM(prhs[0]);
int u = 0;
double* punc_pat_mat = mxGetPr(prhs[0]);
plhs[0] = mxCreateDoubleMatrix(1, n*m , mxREAL);
double* punc_pat_row = mxGetPr(plhs[0]);
mexPrintf("%d Spalten\n", n);
mexPrintf("%d Zeilen\n", m);
for (int ii = 0 ; ii<(n-1) ; ii++ )
{ // line 14
for (int i = 0 ; i<(m-1) ; i
+ ) // line 15
{
punc_pat_row = punc_pat_mat[ii+i*n];
u++;
}
}
}
---------------------------------------------------------------------------------------
It is supposed to work but there is a syntax error concerning the two
for loops. Here is the compiler output:
beispiel.cpp(15) : error C2059: syntax error : ')'
beispiel.cpp(16) : error C2143: syntax error : missing ';' before '{'
I tried a lot but every change doesn't make it better and looks
stupid! What do I wrong? I would be very grateful for your help.
Thanks in advance.
regards, Bernhard