I am trying to extract data calculated in the MATLAB environment into the mex-function set-up in vain. Could someone please point out the error in my code or anything that I am doing wrong?
int *aidx, *idx;const mxArray *m_sort, *m_pctemp;../* Necessary initializations for 'sort' is made and all is well so far */..mexCallMATLAB(2, m_sort, 3, &m_pctemp, "sort"); // Works fine/* Displays the correct data in 'm_sort' */mexCallMATLAB(0, NULL, 1, &m_sort, "disp"); //(double)mexCallMATLAB(0, NULL, 1, &m_sort, "disp"); //(int)aidx = (int *)mxGetData(m_sort);ORaidx = mxGetPr(m_sort);idx = ivector(0, 23); // memory allocation with indices range(0-23)for (i = 1; i <= 24; i++) // Matlab indices is from 1 to 24idx[i-1] = aidx[i]; // Wrong values from aidx here
I will need the array m_sort that holds the indices for further processing. It looks like I am not extracting the values properly. Both the APIs fail to give me the correct values.
I believe using mxGetData with proper casting (int *) is the right way to get the integer data from m_sort.
Am I right? If not, Please tell me what is the right way to do it? or if I should provide more information to get me off this problem.
Thanks in advance.