Trying to create .c file, Variable 'complexMat22' is not fully defined on some execution paths.

Hi, for my final project I need to create a .c file from my matlab code to run on a microcontroller. I keep getting the "Variable complexMat22 is not fully defined on some execution paths" error even though I think I cleared all possible scenarios.
the relevant code lines:
r2=find(complexMat2(:,4));
if isempty(r2)~=1
complexMat22=zeros(length(r2),5);
complexMat22(:,:)=complexMat2(r2,:);
boolean55=1;
.
.
.
if boolean5*boolean55==1
for i=1:length(complexMat22(:,4))
.
.
.
end
I tried to make sure complexMat22 is not empty and in fact exists but I still get the error...
Thanks for the help!

Answers (1)

Shimmy - the error message is telling you that the variable complexMat22 is not being defined for all execution paths. It seems that you are creating it in an if block. Is that the only place? If so, then if this block of code is not executed (because r2 is empty) then complexMat22 will not be defined for the other if block where we iterate over each element in this complex matrix.
Try defining this variable outside of the first if statement as
r2=find(complexMat2(:,4));
complexMat22 = [];
if isempty(r2)~=1
% etc.
end
Now, regardless as to whatever execution path is invoked, the variable complexMat22 will be defined.

Categories

Asked:

on 6 May 2016

Answered:

on 6 May 2016

Community Treasure Hunt

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

Start Hunting!