embedded matlab function error message

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 日

0 投票

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 日

0 投票

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 日

0 投票

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 日
yes, its true here is a link for the flowchart http://www.mediafire.com/view/?2tkvty7sq9d419o
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 8 日
Your code don't correspond to your chart
mado
mado 2013 年 2 月 8 日
why ?? what is the problem could you explain or modify this code?
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 8 日
From your chart, you should do
if V-Vold>0
%your code1
else
%your code2
end
mado
mado 2013 年 2 月 8 日
that's what i exactly did , but cause i don't know how to write if I- Iold==0 return i wrote if I ~=Iold and so on the other branch
mado
mado 2013 年 2 月 8 日
do you have any suggestions ?
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 8 日
Explain, clearly what you don't know to write?
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 8 日
編集済み: Azzi Abdelmalek 2013 年 2 月 8 日
From your chart :
if V>Vold
if I-Iold==0
%do
else
if I>Iold
dvref=Vref+c
else
dvref=Vref-c
end
end
%-------------------------------
else
if dI/dV==-I/V
%do
else
if dI/dV > -I/V
dvref=Vref+c
else
dvref=Vref-c
end
end
end
mado
mado 2013 年 2 月 8 日
if I-Iold==0
%do
do what ??i won't do any thing just i will return to measure i and v and this is not the problem we went far away from the original problem that dvref should be assigned outside if condition , since you saw the flowchart there is no place for dvref outside if condition
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 8 日
編集済み: Azzi Abdelmalek 2013 年 2 月 8 日
just let it as a comment, to make your code readable. The problem is that your code don't correspond to your chart. I've tried to fix it, try it and tell me about it
mado
mado 2013 年 2 月 8 日
what about the error message "Output argument 'dvref' is not assigned on some execution paths."
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 8 日
Well, you said if I-Iold==0, I won't do any thing which means, when the previous expression is true, there is no assignation to your variable dvref. Maybe you should assign to it the previous value or declare it as persistent.
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 日

0 投票

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

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

カテゴリ

ヘルプ センター および File ExchangeGeneral Applications についてさらに検索

タグ

質問済み:

2013 年 2 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by