2D Input Array Mex Input Values don't match

I have 2D Array Input(Prob), but when I debug in C, the values of Prob are not the right ones. When the Matrix Prob(2D) from Matlab looks like links 100010 011101 100101 011001
#include "mex.h"
//#include <new>
typedef struct _complex1{
double real;
double imag;
} complex1;
double abs_square(complex1 value) {
double abs2;
abs2 = value.real*value.real + value.imag*value.imag;
return abs2;
}
double round(double value) {
double round2;
if (value < 0.5)
{
round2 = 0;
}
else
{
round2 = 1;
}
return round2;
}
/* Input Arguments */
#define QAM_IN prhs[0]
#define Prob_IN prhs[1]
//#define Bit_IN prhs[2]
/* Output Arguments */
#define Prob_QAM_OUT plhs[0]
void nur_hd_c(
complex1 QAM[64],
//int Bit[64][6],
double Prob[2][6],
//double Prob[6],
double Prob_QAM[64])
{
//double Prob_QAM[64] = {0};
int i;
int hd[6];
const short binary_factor[6] = { 32, 16, 8, 4, 2, 1 };
int constell_indx;
for (i = 0; i<6; i++) {
//hd[i] = round(Prob[1][i]);
hd[i] = (int)round(Prob[1][i]);
//hd[i] = (int)round(Prob[i]);
constell_indx = hd[i] * binary_factor[i] + constell_indx;
}constell_indx = constell_indx + 1;
//Prob_QAM[constell_indx - 1] = Bit[29][0];
//Prob_QAM[constell_indx - 1] = Bit[constell_indx - 1][0];
//Prob_QAM[constell_indx - 1] = Prob[Bit[constell_indx - 1][0]][0];
// for (i = 0; i<64; i++) {
// Prob_QAM[i] = 3 * abs_square(QAM[i]);
// }
}
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray*prhs[] )
{
complex1 QAM[64]; /*1x64 input matrix */
double Prob[2][6];
//double Prob[6];
//double Bit[64][6];
size_t ncols; /* size of matrix QAM */
//double *bit_in; /* input matrix */
//double * Bit_aux;
//double(*Prob_aux)[2][6];
///double ** Prob_aux;
double * QAMR_aux;
double * QAMI_aux;
double * Prob_QAM; /* output matrix */
size_t m, n; /* size of matrix Prob */
int i,j;
/* create a pointer to the real data in the input matrix */
QAMR_aux = mxGetPr(QAM_IN);
QAMI_aux = mxGetPi(QAM_IN);
//Prob_aux = mxGetPr(Prob_IN);
//Bit_aux = mxGetPr(Bit_IN);
/* get dimensions of the input matrix */
ncols = mxGetN(prhs[0]);
/* create the output matrix */
Prob_QAM_OUT = mxCreateDoubleMatrix(1, (mwSize)ncols, mxREAL);
/* get a pointer to the real data in the output matrix */
Prob_QAM = mxGetPr(Prob_QAM_OUT);
m = mxGetM(Prob_IN);
n = mxGetN(Prob_IN);
/* Copy the input variables to the local ones */
for (i = 0; i<ncols; i++){
/* Copy the input y to the variable */
QAM[i].real = QAMR_aux[i];
QAM[i].imag = QAMI_aux[i];
}
for (i = 0; i<2; i++){
for (j = 0; j < 6; j++){
/* Copy the input y to the variable */
Prob[i][j] = mxGetPr(Prob_IN)[j + i*6]; //Prob_aux[i][j];
//Prob[i] = Prob_aux[i];
}
}
/* call the computational routine */
nur_hd_c(QAM, Prob, Prob_QAM);
}

1 commentaire

James Tursa
James Tursa le 19 Sep 2016
Can you be more specific about what is not matching? E.g., can you give some small sample inputs and what you are expecting for outputs? What, exactly, is not matching up with what you expected?

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Centre d'aide et File Exchange

Tags

Question posée :

le 10 Mai 2016

Commenté :

le 19 Sep 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by