embedded matlab function error message
Ältere Kommentare anzeigen
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
Antworten (4)
Walter Roberson
am 8 Feb. 2013
0 Stimmen
In your "if I~=Iold" case you do not assign anything to dvref .
1 Kommentar
mado
am 8 Feb. 2013
mado
am 8 Feb. 2013
0 Stimmen
Azzi Abdelmalek
am 8 Feb. 2013
0 Stimmen
Are you sur one of these two expression
- if V==Vold
- elseif dI/dV~=-I/V
is true for each step?
14 Kommentare
mado
am 8 Feb. 2013
Azzi Abdelmalek
am 8 Feb. 2013
Your code don't correspond to your chart
mado
am 8 Feb. 2013
Azzi Abdelmalek
am 8 Feb. 2013
From your chart, you should do
if V-Vold>0
%your code1
else
%your code2
end
mado
am 8 Feb. 2013
mado
am 8 Feb. 2013
Azzi Abdelmalek
am 8 Feb. 2013
Explain, clearly what you don't know to write?
Azzi Abdelmalek
am 8 Feb. 2013
Bearbeitet: Azzi Abdelmalek
am 8 Feb. 2013
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
am 8 Feb. 2013
Azzi Abdelmalek
am 8 Feb. 2013
Bearbeitet: Azzi Abdelmalek
am 8 Feb. 2013
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
am 8 Feb. 2013
Azzi Abdelmalek
am 8 Feb. 2013
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
am 8 Feb. 2013
Azzi Abdelmalek
am 8 Feb. 2013
Bearbeitet: Azzi Abdelmalek
am 8 Feb. 2013
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
am 8 Feb. 2013
0 Stimmen
2 Kommentare
Walter Roberson
am 8 Feb. 2013
You cannot just return without having assigned something to dvref .
mado
am 9 Feb. 2013
Kategorien
Mehr zu General Applications finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!