It took me some time until I figured out how to pass a struct to a mex file and especially how to get out the values.
To get the values from the struct following lines are important:
/* get the values from the struct */
const mxArray *mxTmp;
double *tmp;
mxTmp = mxGetField(prhs[1],0,"par1");
tmp = mxGetPr(mxTmp);
Here the full code
To compile the code, put the code in a file, e.g. passStruct2Mex_MEX.c and use following command within matlab
cd /path/to/file
mex passStruct2Mex_MEX.c
To test the code you can use following matlab script
% test the mex function
approxPar.par1 = [1,2,3,4];
approxPar.par2 = [10,20,30,40];
approxPar.par3 = [100,200,300,400];
approxPar.delta = 0.02;
distMtx = rand(375,375,375);
triangulared_distMtx = zeros(375,375,375);
passStruct2Mex_MEX(distMtx,approxPar,triangulared_distMtx);
keyboard
It should print out the following lines
Is Structure or Not: 1
1st field name: par1
2ns field name: par2
3rd field name: par3
4th field name: delta
5th field name: (null)
----- printing values of par1 -----
par1[0] = 1.00
par1[1] = 2.00
par1[2] = 3.00
par1[3] = 4.00
Comments
Sukruth (not verified)
Fri, 08/21/2015 - 10:00
Permalink
Code errors
Hi there are a few execution errors while running the program such as syntax errors and undeclared identifiers.Hope you could give me a elaborate explaination in executing this file
Add new comment