필터 지우기
필터 지우기

Accessing Non-Scalar Arrays with ceval

조회 수: 3 (최근 30일)
Greg
Greg 2012년 6월 11일
Hi,
I'm trying to use the Matlab "mat" and "mx" C-libraries to use .mat-files inside of a Matlab function I'm compiling with the Matlab Coder. I can do this successfully for a scalar variable, but I'm having trouble getting non-scalar arrays in. Because coder.ceval can only return a scalar, my best guess of how to do this at the moment is to use the C "memcpy" function with a coder.wref input.
Here's what I've got right now, referencing a .mat-file "testmat.mat" that has one variable in it, a 1x4 double:
y = ones(1,4);
SS_Table_File = coder.opaque('MATFile *');
rr = ['r',char(0)];
SS_Table_file = coder.ceval('matOpen','testmat.mat',rr);
Xp = coder.opaque('mxArray *');
XX = ['X',char(0)];
Xp = coder.ceval('matGetVariable',SS_Table_file,XX);
coder.ceval('matClose',SS_Table_file);
yp = coder.opaque('double *');
yp = coder.ceval('mxGetPr',Xp);
coder.ceval('memcpy',coder.wref(y),yp,int32(4*8));
This currently compiles OK but then produces a segfault (or some other fatal error that crashes Matlab) when I run it.

채택된 답변

Greg
Greg 2012년 6월 13일
Apparently the above code would actually work OK if size_t were a 32-bit integer (which I had assumed it was). On my 64-bit linux machine that defines size_t as an unsigned long int (a uint64), I have to do something like this since the Matlab coder doesn't support 64-bit integers:
sz = coder.opaque('size_t');
sz = coder.ceval('(size_t)',4*8);
coder.ceval('memcpy',coder.wref(y),yp,sz);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by