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 个)
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
2013-2-8
Azzi Abdelmalek
2013-2-8
Your code don't correspond to your chart
mado
2013-2-8
Azzi Abdelmalek
2013-2-8
From your chart, you should do
if V-Vold>0
%your code1
else
%your code2
end
mado
2013-2-8
mado
2013-2-8
Azzi Abdelmalek
2013-2-8
Explain, clearly what you don't know to write?
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
2013-2-8
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
2013-2-8
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
2013-2-8
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
2013-2-8
0 个投票
2 个评论
Walter Roberson
2013-2-8
You cannot just return without having assigned something to dvref .
mado
2013-2-9
类别
在 帮助中心 和 File Exchange 中查找有关 General Applications 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!