Variable 'D' is not fully defined on some execution paths. Why?

Hello. I'm using the following code in embedded matlab in simulink. And I,m getting the message that Variable 'D' is not fully defined on some execution paths. And i don't know what is the problem in code.
function D = mpp(V,I,T)
Dinit = 0.7;
delD = 0.001;
Dmax = 0.9;
Dmin = 0.1;
persistent P0 V0 D0 n;
if isempty(P0)
P0 = 0;
V0 = 0;
n = 1;
D0 = Dinit;
end
P = V*I;
dP = P - P0;
dV = V - V0;
if(T>0.02*n)
n=n+1;
if(dP*dV > 0)
D = D0 - delD;
elseif(dP*dV < 0)
D = D0 + delD;
end
else
D = D0;
end
if D>=Dmax | D<=Dmin
D = D0;
end
V0 = V;
P0 = P;
D0 = D;

답변 (1개)

Walter Roberson
Walter Roberson 2017년 6월 2일
if(dP*dV > 0)
D = D0 - delD;
elseif(dP*dV < 0)
D = D0 + delD;
end
does not assign to D if dp*dV == 0

댓글 수: 4

Steel it shows the same message for the following portion of code as before
if D>=Dmax | D<=Dmin
Walter Roberson
Walter Roberson 2017년 6월 3일
편집: Walter Roberson 2017년 6월 3일
What did you change the code to? The code you posted has a problem in the situation that dP == 0 or dV == 0.
hello! now I have the same problem. How did you change it ?
Look at the simple example below. What does fun343107 do when x is exactly equal to 0? That behavior is undefined, so you'll receive a similar type of error as the original poster. To fix it, add code to handle the case where x is exactly equal to 0 in fun343107; that's the code that's commented out in the function.
Look for this same type of situation in your code.
y = fun343107(1)
y = 'positive'
y = fun343107(-1)
y = 'negative'
y = fun343107(0)
Output argument "y" (and possibly others) not assigned a value in the execution with "solution>fun343107" function.
function y = fun343107(x)
if x > 0
y = 'positive';
elseif x < 0
y = 'negative';
% else
% y = 'zero';
end
end

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

카테고리

도움말 센터File Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

질문:

2017년 6월 2일

댓글:

2022년 10월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by