Variable 'a' is undefined on some execution paths. Why?

I'm using the block named Embedded MATLAB (that link the simulink to matlab) and when I try to run the code above, return the message error: "Variable 'a' is undefined on some execution paths". Besides that, other message appears: "Parsing successful for machine: "teste1_05mar13"(#17)" What does it mean?
function y = fcn(ia,va,t)
%#eml
p = ia*va;
N=1000;
if t <= 1.0e-6
a = 0;
b = 0;
end
b = a-0.01; %"b" is the value of the same "a", but is a value that precedes in 0.01 the value "a"
a = b + (p -b)/N;
y=a;
Thanks

1 comentario

Caroline Rosa
Caroline Rosa el 8 de Mzo. de 2013
Editada: Azzi Abdelmalek el 8 de Mzo. de 2013
function y = fcn(ia,va,t)
p = ia*va;
N=1000;
if t <= 1.0e-6
a = 0;
b = 0;
end
b = a-0.01;
a = b + (p -b)/N;
y=a;
In order to understand better. thanks

Iniciar sesión para comentar.

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 8 de Mzo. de 2013
Editada: Azzi Abdelmalek el 8 de Mzo. de 2013

2 votos

when if t <= 1.0e-6 is false a and b are unknown
You should declare a and b persistent

3 comentarios

Azzi Abdelmalek
Azzi Abdelmalek el 8 de Mzo. de 2013
Editada: Azzi Abdelmalek el 8 de Mzo. de 2013
function y = fcn(ia,va,t)
persistent a b;
if isempty(a) % Initialization
a=0;
b=0;
end
p = ia*va;
N=1000;
if t <= 1.0e-6 a = 0;
b = 0;
end
b = a-0.01;
a = b + (p -b)/N;
y=a;
thanks for your help Azzi. now it works. Thanks so much
Hi I want to run this code about MPPT
%%%%
function D=inc(V,I)
Dinit=.574;
deltaD=0.001;
persistent Va Da Ia;
if isempty(Da)
Va=42.64;
Ia=2;
Da=Dinit;
end
dV=V-Va;
dI=I-Ia;
if dV== 0
if dI~=0
else
if dI>0
D=Da-deltaD;
else
D=Da+deltaD;
end
end
else
if dI/dV==-I/V
else
if dI/dV>-I/V
D=Da-deltaD;
else
D=Da+deltaD;
end
end
end
Da=D;
Va=V;
Ia=I;
but Matlab shows this error
Variable 'D' is not fully defined on some execution paths.

Iniciar sesión para comentar.

Más respuestas (1)

Ryad BOUKHARI
Ryad BOUKHARI el 25 de Abr. de 2017

0 votos

Hello,
I faced the same problem, and it works.
Thank you Abdelmalek.

Categorías

Más información sobre MATLAB Coder en Centro de ayuda y File Exchange.

Preguntada:

el 8 de Mzo. de 2013

Comentada:

el 15 de Sept. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by