필터 지우기
필터 지우기

embedded matlab function error message

조회 수: 1 (최근 30일)
mado
mado 2013년 2월 8일
i have this error message
"Output argument 'dvref' is not assigned on some execution paths."
when executing this code
function dvref =IC(V,I)
persistent Vref Vold Iold c;
if isempty(Vold)
Vold=0; %initialized only once in the beginning
end
if isempty(Iold)
Iold=0; %initialized only once in the beginning
end
if isempty(c)
c = .1; %initialized only once in the beginning
end
if isempty(Vref)
Vref=.5; %initialized only once in the beginning
end
dI=I-Iold;
dV=V-Vold;
if V==Vold
if I~=Iold
elseif I>Iold
dvref=Vref-c
else dvref=Vref+c
end
elseif dI/dV~=-I/V
if dI/dV > -I/V
dvref=Vref-c
else
dvref=Vref+c
end
end
Iold=I
Vold=V

답변 (4개)

Walter Roberson
Walter Roberson 2013년 2월 8일
In your "if I~=Iold" case you do not assign anything to dvref .
  댓글 수: 1
mado
mado 2013년 2월 8일
actually this is not the problem i tried it but in a vain , error is still there.

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


mado
mado 2013년 2월 8일
the answer is that dvref should be outside the if condition but in my flowchart it'snot outside the if condition ,so i don't know how to implement it any one help

Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 8일
Are you sur one of these two expression
  • if V==Vold
  • elseif dI/dV~=-I/V
is true for each step?
  댓글 수: 14
mado
mado 2013년 2월 8일
dvref can't be declared on persistent as it is the output of the embedded function.
Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 8일
편집: Azzi Abdelmalek 2013년 2월 8일
You can use a unit delay block to get the previous value of dvref. Name it dvref_old, then in your code instead of "Doing nothing" you will do:
dvref=dvref_old

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


mado
mado 2013년 2월 8일
if I-Iold=0 if yes return if no check the next step i don't know "return" here is right or not, so i reversed it i checked the inequality and so on
  댓글 수: 2
Walter Roberson
Walter Roberson 2013년 2월 8일
You cannot just return without having assigned something to dvref .
mado
mado 2013년 2월 9일
ok , how to do this using simulink i think it will be easier

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

카테고리

Help CenterFile Exchange에서 Configure and View Diagnostics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by