Matlab Coder : codegen for mvnrnd

조회 수: 3 (최근 30일)
Jane Jean
Jane Jean 2012년 4월 9일
Hi, I'm trying to generate standalone C code of the mvnrnd function in Matlab with Matlab Coder. By doing so, I keep getting error:
>> mu = [1 -1]
mu =
1 -1
>> sigma = [.9 .4; .4 .3]
sigma =
0.9000 0.4000
0.4000 0.3000
>> codegen -config:lib -report -c mvnrnd1.m -args {mu,sigma}
??? The input matrix must be variable-size in both dimensions when nargout == 2
How do I insert variable-size matrix in -args? Thank you!

답변 (2개)

Mike Hosea
Mike Hosea 2012년 4월 9일
Instead of using sigma in that -args list, use
sigma_type = coder.typeof(0,[2,2],[true,true])
This means the type is double and real (that is the type of the first argument "0"). The second argument says that the array is up to 2-by-2, and the third argument says that both dimensions are variable in size.
Good luck. The conversion looks doable, but there may be other snags, and it's the type of function where I'd probably do a lot of re-writing to make it efficient for code generation (e.g., I'd write a little loop to calculate sum(D<0) instead of creating a logical array and then summing it). -- Mike
  댓글 수: 8
Jane Jean
Jane Jean 2012년 4월 15일
I've added a line at the beginning of the function :
coder.extrinsic('cholcov', 'message');
Matlab crashes before generating the mexFunction. What had happened now?
Jane Jean
Jane Jean 2012년 4월 15일
mu = coder.typeof(0,[500,500],[true,true]);
sigma = coder.typeof(0,[500,500],[true,true]);
codegen -report mvnrnd1.m -args {mu, sigma};
Here above are the lines that i used to generate mexFunction.

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


Jane Jean
Jane Jean 2012년 4월 15일
I have managed to the eliminate the errors which caused the crash by defining the size of the output of cholcov in mvnrnd.m script.
Now the mexFunction works perfectly. :) Thank you for your help.
  댓글 수: 1
Mike Hosea
Mike Hosea 2012년 4월 16일
I'm glad, but I'm a little confused. If you are just building a mex function, why not make MVNRND extrinsic?

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

카테고리

Help CenterFile Exchange에서 Execution Speed에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by