Hi,
I've got some troubles trying to use some mex files. The first one is
that if I
include oct.h file, it cannot compile as it doesn't find some files
such as
cassert. In fact, I think this is because include files of octave are
under
/usr/local/include whereas C and C++ ones are under /usr/include. But
I don't
know how to precise where to find libraries.
Well, I can still compile one of my functions without the oct.h. But I
can't use
it as it doesn't find mxGetDimensions.
To try to be a bit more clear, I send you below the function I've
tested:
/********************************************************************/
/********************************************************************/
/*#include "oct.h"*/
#include "mex.h"
#include <math.h>
void normalitzar(double *x1, double *y1, const int *dim_array) {
int i, j;
double tmp;
double *x2, *x3, *y2, *y3;
x2 = x1 + dim_array[0]*dim_array[1];
x3 = x2 + dim_array[0]*dim_array[1];
y2 = y1 + dim_array[0]*dim_array[1];
y3 = y2 + dim_array[0]*dim_array[1];
for( i = 0; i < dim_array[0]; i++) {
for( j = 0; j < dim_array[1]; j++) {
if (tmp = sqrt( *x1**x1 + *x2**x2 + *x3**x3 )) {;
*y1++ = *x1++ / tmp;
*y2++ = *x2++ / tmp;
*y3++ = *x3++ / tmp;
} else {
*y1++ = *x1++;
*y2++ = *x2++;
*y3++ = *x3++;
}
}
}
}
/* The gateway routine */
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
double *y, *x;
int elements, number_of_dims;
const int *dim_array;
/* Check for proper number of arguments. */
/* NOTE: You do not need an else statement when using
mexErrMsgTxt within an if statement. It will never
get to the else statement if mexErrMsgTxt is executed.
(mexErrMsgTxt breaks you out of the MEX-file.)
*/
if (nrhs != 1)
mexErrMsgTxt("One inputs required.");
/* Check data type of input argument. */
if (!(mxIsDouble(prhs[0]))) {
mexErrMsgTxt("Input array must be of type double.");
}
/* Get the number of elements in the input argument. */
elements = mxGetNumberOfElements(prhs[0]);
/* Create a pointer to the input matrix x. */
x = mxGetPr(prhs[0]);
/* Get the number of dimensions in the input argument.
Allocate the space for the return argument */
number_of_dims = mxGetNumberOfDimensions(prhs[0]);
dim_array = mxGetDimensions(prhs[0]);
plhs[0] = mxCreateDoubleMatrix(elements, number_of_dims, mxREAL);
/* Create a C pointer to a copy of the output matrix. */
y = mxGetPr(plhs[0]);
/* Get the number of dimensions in the input argument. */
dim_array = mxGetDimensions(prhs[0]);
mxSetDimensions(plhs[0], dim_array, number_of_dims);
/* Call the C subroutine. */
normalitzar(x, y, dim_array);
}
To test it, a matrix like X=rand(100,100,3) should be passed.
Thanks,
Carine.
-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------