Coder and passing extra parameters

조회 수: 3 (최근 30일)
Joseph
Joseph 2011년 9월 18일
Hi all,
I have been trying to speed up the passing of extra parameters to a function that is used in fzero(). I have been trying to create code that is compatible with and can be compiled by the coder. Since nested functions and function handles aren't compatible I have been trying to get the following code compiled.
function z = RxEqNest2(z1,pin2,pin3,pT,pVpore)%#codegen
global in2 in3 T Vpore
in2=pin2;
in3=pin3;
T=pT;
Vpore=pVpore;
z = fzero(@RxEqPoly2,z1);
end
function out1 = RxEqPoly2(z)
global in2 in3 T Vpore
%RXEQPOLY2
% OUT1 = RXEQPOLY2(Z1,IN2,IN3,T,VPORE)
% This function was generated by the Symbolic Math Toolbox version 5.7.
% 15-Sep-2011 22:07:14
Keq1 = in2(:,1);
Keq2 = in2(:,2);
Keq3 = in2(:,3);
Ot = in3(:,2);
t107 = z.^2;
out1 = T.*t107.*(5.774280410608897e15./1.7592186044416e13)+Ot.^2.*T.*(5.774280410608897e15./7.0368744177664e13)+Keq2.*T.*t107.*(5.774280410608897e15./8.796093022208e12)-Ot.*T.*z.*(5.774280410608897e15./1.7592186044416e13)+Keq2.^2.*T.*t107.*(5.774280410608897e15./1.7592186044416e13)-Keq1.^2.*Vpore.*z-Keq3.^2.*Vpore.*z-Keq1.*Keq3.*Vpore.*z.*2.0-Keq2.*Ot.*T.*z.*(5.774280410608897e15./1.7592186044416e13);
end
I get errors during the compilation of the subfunction, saying that it can not find size declarations of in2,in3,T. How can passing parameters efficiently be done when this step is a major bottleneck compared the time spent evaluating the function.
Thanks
  댓글 수: 1
Joseph
Joseph 2011년 9월 18일
Error message:
Could not find initial value for global variable 'in2'.

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

채택된 답변

Alexander Bottema
Alexander Bottema 2011년 9월 19일
Hello Joseph,
Could you show us the 'codegen' command you're using to compile your code with? You need to use '-globals' to specify initial values for the global variables (even though these values will not be used). The initial values are used to determine the class/size/complexness of the global variables.
Thanks, Alexander
  댓글 수: 1
Joseph
Joseph 2011년 9월 19일
I didn't realize to do that because the variables were declared and wanted to limit the scope of them to the mex function, but thanks for the clarification. I tend to minimize my use of globals but didnt know another way to pass extra parameters and still be compatible with the coder. I used this:
codegen RxEqNest2 -args {1,Keq{1},Elements_eg,T_eg,Vpore_eg} -globals {'in2',Keq{1},'in3',Elements_eg,'T',T_eg,'Vpore',Vpore_eg}

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Generating Code에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by