필터 지우기
필터 지우기

Data extraction from MATLAB to mex-function setup

조회 수: 1 (최근 30일)
Rajaram B S R
Rajaram B S R 2011년 11월 4일
Hi all,
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[2], *m_pctemp[3];
../* 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[0], "disp"); //(double)
mexCallMATLAB(0, NULL, 1, &m_sort[1], "disp"); //(int)
aidx = (int *)mxGetData(m_sort[1]);
OR
aidx = mxGetPr(m_sort[1]);
idx = ivector(0, 23); // memory allocation with indices range(0-23)
for (i = 1; i <= 24; i++) // Matlab indices is from 1 to 24
idx[i-1] = aidx[i]; // Wrong values from aidx[] here
I will need the array m_sort[1] 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[1].
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.

채택된 답변

Jan
Jan 2011년 11월 4일
The sorting index is a DOUBLE vector in Matlab. Therefore you need:
int *idx;
double *aidx;
aidx = mxGetPr(m_sort[1]);
...
idx[i-1] = (int) aidx[i];
  댓글 수: 4
Jan
Jan 2011년 11월 7일
@Rajaram: Of course the documentation explains this. It might be hard to find without using the mathcing keywords.
The type of the *returned* arrays is defined inside the Mex file. The type of the input arrays can be checked by rge commands Kaustubha has mentioned already, and by mxIsDouble, mxIsSingle etc.
Rajaram B S R
Rajaram B S R 2011년 11월 9일
Thank you, Kaustubha and Jan.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by