??? Unable to determine that every element of 'C1{:}' is assigned before this line.

7 ビュー (過去 30 日間)
Kanha Srivastav
Kanha Srivastav 2020 年 11 月 2 日
コメント済み: delil codes 2021 年 4 月 26 日
I am running a codegen command:
codegen SplitBregDebP.m -args {g,ker, mu,lambda,tol,frame,Level,wLevel,maxit,img} -report
and am getting the error above for the code:
C = cell(1,nD);
for c = 1:Level
C{c} = cell(nD-1);
for i = 1:nD-1
for j = 1:nD-1
C{c}{i,j} = zeros(m,n);
end
end
end
C1 = coder.nullcopy(C);
coder.varsize('C1');
b1 = coder.nullcopy(b);
d1 = coder.nullcopy(d);
error = 0.0;
deltab = zeros(m,n);
for nstep=1:maxit
for innerstep=1:1
% solve u.
for ki=1:Level
for ji=1:nD-1
for jj=1:nD-1
C1{ki}{ji,jj}=d1{ki}{ji,jj}-b1{ki}{ji,jj};
end
end
end
u=abs(ifft2(fft2(lambda*FraRecMultiLevel(C1,R,Level)+BTg)./eigenP)); %converted to non-complex %new error Codegen requires that every cell-array element contained in 'C' be assigned a value before being passed into 'FraRecMultiLevel'. Check assignments to element(s):
%u = zeros(m,n);
% solve d
% size(FraDecMultiLevel(u,D,Level))
C1=FraDecMultiLevel(u,D,Level); %changed name of variable %same LHS size != RHS error
for ki=1:Level
for ji=1:nD-1
for jj=1:nD-1
d1{ki}{ji,jj}=wthresh(C1{ki}{ji,jj}+b1{ki}{ji,jj},'s',muLevel{ki}{ji,jj}/lambda); %Unable to determine that every element of 'C{:}' is assigned before this line.
end
end
end
end
error=0;
for ki=1:Level
for ji=1:nD-1
for jj=1:nD-1
if ((ji~=1)|(jj~=1))|(ki==Level)
deltab=C1{ki}{ji,jj}-d1{ki}{ji,jj};
error=error+norm(deltab,'fro')^2;
b1{ki}{ji,jj}=b1{ki}{ji,jj}+deltab;
end
end
end
end
error=sqrt(error)/normg;
%disp(['error on step ' num2str(nstep) ' is ' num2str(error) ', and SNR
%is ' num2str(snr(u,img))]); %shouldnt show in codegen
if error<tol
break;
end
end
I have gone through the documentation for this error (https://www.mathworks.com/help/simulink/ug/unable-to-determine-that-every-element-of-cell-array-is-assigned.html) and still cannot find a solution to this problem. Seeing how this problem persists for C1, I am also assuming that this same error will show up for d1, b1, and error. Is there any quick solution that I am missing for this problem or will I have to modify the code such that all instances of cell arrays are removed from the code?

回答 (1 件)

Darshan Ramakant Bhat
Darshan Ramakant Bhat 2020 年 11 月 3 日
This is happening because of the assignment
C1=FraDecMultiLevel(u,D,Level);
"FraDecMultiLevel" is returning a multi dimensional cell array and the MATLAB Coder is not able to determine if all the eliments are being written to this cell array before accessing the values.
So you need to explicitely write a loop to assign the values of the cell array at the function where it's values are accessed.
Also, the relation between the nD and Level is not clear in the function "getwThresh".
I have modified the code (please note that I am not aware of the algorithm, my modification may lead to wrong answer) to achieve the above rule. Please compare the code before and after my modification.
Tips :
  • Try to simplify the algorithm without returning multi-dimensional cell arrays from the functions.
  • Use coder.nullcopy() with caution. This is just forcing the MATLAB Coder to treat as if all the values are initialized. You have to make sure that all the values are initialized before using the variable. Otherwise it may result in a non-deterministic behavior. See https://www.mathworks.com/help/coder/ref/coder.nullcopy.html
  1 件のコメント
delil codes
delil codes 2021 年 4 月 26 日
Hello, I have a same problem, do u have the solution;
https://www.mathworks.com/matlabcentral/answers/813220-simulink-matlab-function-using-cell-problem?s_tid=prof_contriblnk

サインインしてコメントする。

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by