2012-02-06 1 views
3

MATLAB API를 사용하여 'MAT 파일'에서 데이터를 읽을 때 3D 배열의 'z'치수를 알 수있는 방법이 있는지 알고 싶습니다. 위해, 깊이 값을 가져올 때 내가 붙어있어C++을 사용하여 MAT 파일에서 3D 배열 가져 오기

double* importMATFile(const char* i_file) 
{ 
    MATFile *pMF; 
    // open MAT-file 
    pMF = matOpen(i_file, "r"); 
    // check for file errors 

    // Matlab Array Data 
    mxArray *mArrayData; 
    // Matlab Variable Name 
    const char* mVarName = NULL; 
    // read data from file 
    mArrayData = matGetNextVariable(pMF, &mVarName); 

    // pointer to mxArray data 
    double *dataPtr; 
    dataPtr = (double*) mxGetPr(mArrayData); 

    // NOTE MATLAB work in COLUMN-MAJOR order 

    // dimension of the array : rows 
    int32_t NROWS = mxGetM(mArrayData); 
    // Right now the z dimension must be known a priori 
    int32_t NDEPTH = 32 
    // dimension of the array : cols 
    int32_t NCOLS = mxGetN(mArrayData)/NDEPTH; 

    return dataPtr; 
} 

열 수를 알고 다음과 같이 나는 파일에서 데이터를로드하는 함수를 구현했습니다. 나는 함수의 결과가 mxGetNumberOfDimensions (mArrayData)이 이라는 것을 알았으므로 API는 3 차원을 알고 있습니다.

답변

2

나는 당신이 원하는 것이 mxGetDimensions이라고 믿습니다. 각 치수의 크기를 반환합니다. 이 기능은 3이 아닌 여러 차원에서 작동해야합니다.

관련 문제