Matlab Coder. Function call failed. The first assignment to a local variable determines its class.

12 次查看(过去 30 天)
I get the following error messages trying to generate C code with Matlab Coder.
3
logistic_dbcv > pcacvdbl 335 Function call failed.
4
logistic_dbcv > pcacvdbl 335 Undefined function or variable 'urt'. The first assignment to a local variable determines its class.
5
logistic_dbcv > pcacvdbl 335 Undefined function or variable 'z'. The first assignment to a local variable determines its class.
6
logistic_dbcv > pcacvdbl 336 Undefined function or variable 'urt'. The first assignment to a local variable determines its class.
7
logistic_dbcv > pcacvdbl 336 Undefined function or variable 'udf'. The first assignment to a local variable determines its class.
<<etc....>>
There are no problems with the Code Generation Readiness report (score=5 and no problems found).
The errors seem to correspond to the first two “if”/ “elseif” alternatives in the below "if statement" where the relevant code can be found. These correspond to two special cases which occur with very low probability. I assume this must be the reason why running the code does not allow Coder to identify the variable types – because these special cases did not occur in the testing file.
I could try to make a more extensive testing file which contains examples in which these special cases do occur – and then perhaps Coder would be able to solve the problem. Is there another way to declare the variables “urt”, “z”, “udf”, “z” to Coder? I am also asking the question since the variable “urt”, “udf” and “ud” e.g. are all of the same type. So writing an extensive testing file seems like an expensive and difficult way to solve the problem.
334if min(d(1:(n-1))-d(2:n)) < toles
334
335 [urt,z]=dflreig(u,d,z,n,toles);
336 [udf,e,z,modif,nn]=dflrsco(urt,d,z,n,rho,toles);
337 [ud,edd,~]=mdfpcadb(i,urt,udf,d,e,z,rho,mm,modif,nn,w,nr,nu,tol2,tau);
338elseif minabsz < toles || minabsz^2 < (10e-20)*rho;
339
340 [udf,e,z,modif,nn]=dflrsco(u,d,z,n,rho,toles);
341 [ud,edd,~]=mdfpcadb(i,u,udf,d,e,z,rho,mm,modif,nn,w,nr,nu,tol2,tau);
342else
343 [ud,edd,~]=mdfpcadb(i,u,u,d,d,z,rho,mm,modif,n,w,nr,nu,tol2,tau); 344end;
  3 个评论
Walter Roberson
Walter Roberson 2014-3-28
The user did not format the code so one of the logical connects was getting mis-formatted. There is a || between the two parts.
Ketan
Ketan 2014-3-29
编辑:Ketan 2014-3-30
Another suggestion is that the first error "335 Function call failed." might mean that there is an issue related to the implementation of "dflreig".
Do you have any error messages that point to the internals of this function? That may help understand this issue. How about providing a screenshot of the "All Messages" portion of the coder report?

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2014-3-28
Assign something (with the right data type) before you reach the conditional section.
You assign something to z if the first "if" condition is satisfied. in the second "elseif" condition you use z in the dflrsco() call without having assigned anything to it first. The Coder is not going to trace through the flow to prove that the first condition must always be true before the elseif can happen. The portion of the code you show does not contain enough for us to evaluate whether all possible paths through will initialize z before it is used. So give the Coder a hint and initialize z before the block of code. For example you might want to assign NaN to it and then in the elseif section assert() that it is non-NaN.

产品

Community Treasure Hunt

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

Start Hunting!

Translated by