LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

how to copy data into and get data out of mwArray

This question is not really about LabVIEW, but I am sure I can get an answer here sooner than anywhere else. 

 

I recently compiled a m code into a C++ shared library using the Matlab compiler. I am trying to call this Matlab-generated code in my C++ project. Then I found this mwArray type which I never used before. Here is the C code.  I need to copy the 'image2DArray' into the 'im', run the code, and get the data out of the 'result' into a C++ 2D array so that it can be passed on to the next C code.

 

But the code does not work. It has a memory leak issue. I have been searching for how to use 'mwArray', but it does not seem to be an easy tutorial for this. Anybody here compiles the Matlab code and uses it in a C code? 

 

void contourcGenerate(double *c, double *image2DArray, int imageWidth, int imageHeight, double contourLevel)

{
    mwArray im;
    mwArray a(0.8);
    mwArray result;
	
	//create the input data
	//im.SetData(image2DArray,imageWidth*imageHeight);
	//im=mxCreateDoubleMatrix(imageWidth,imageHeight,mxREAL);
	int i=0,j=0;
	for(i=0;i<imageWidth;i++)
	{
		for(j=0;j<imageHeight;j++)
		{
			im(i*imageWidth+j)=image2DArray[i*imageWidth+j];
		}
	}
	//a.SetData(&contourLevel,1); 
      //Call Matlab-generated
	generateContour(1, result,im,a,a);
      //Get data out 
	result.GetData(c,1);
}
0 Kudos
Message 1 of 1
(7,471 Views)