"Undefined function or variable 'PA'. The first assignment to a local variable determines its class.". Why do I keep getting this error?
10 ビュー (過去 30 日間)
古いコメントを表示
I have a function for my MPPT which i will implement or arduino using simulink but whenever i try to run the simulation it shows me this error "Undefined function or variable 'PA'. The first assignment to a local variable determines its class."
function D= fcn(VA,IA)
persistent VAprev
persistent PAprev
persistent Dprev
if isempty(VAprev)
VAprev = 0;
end
if isempty(PAprev)
PAprev = 0;
end
if isempty(Dprev)
Dprev = 0.5;
end
dataType = 'double';
double(PA);
double(IA);
D=Dprev;
PA=VA*IA;
DeltaVA= VA-VAprev;
DeltaPA= PA-PAprev;
if DeltaPA>0
if DeltaVA>0
D=Dprev - 0.0001;
elseif DeltaVA<0
D=Dprev +0.0001;
end
elseif DeltaPA<0
if DeltaVA>0
D=Dprev+0.0001;
elseif DeltaVA<0
D=Dprev-0.0001;
end
end
if D>0.9
D=0.9;
elseif D<0
D=0;
end
VAprev=VA;
PAprev=PA;
Dprev=D;
0 件のコメント
回答 (1 件)
Walter Roberson
2022 年 8 月 3 日
double(PA);
double(IA);
D=Dprev;
PA=VA*IA;
You do something (useless) with PA before you assign to it.
Remember in MATLAB a type name used like a function is not a type declaration, it is a type conversion.
PA = 0;
might be suitable
2 件のコメント
Walter Roberson
2022 年 8 月 4 日
function D = fcn(VA,IA)
persistent VAprev
persistent PAprev
persistent Dprev
if isempty(VAprev)
VAprev = 0;
end
if isempty(PAprev)
PAprev = 0;
end
if isempty(Dprev)
Dprev = 0.5;
end
D = 0;
IA = 0;
PA = 0;
PV = 0;
DeltaVA = 0;
DeltaPA = 0;
D = Dprev;
PA = VA*IA;
DeltaVA = VA-VAprev;
DeltaPA = PA-PAprev;
if DeltaPA>0
if DeltaVA>0
D = Dprev - 0.0001;
elseif DeltaVA<0
D = Dprev + 0.0001;
end
elseif DeltaPA<0
if DeltaVA>0
D = Dprev + 0.0001;
elseif DeltaVA<0
D = Dprev - 0.0001;
end
end
if D>0.9
D = 0.9;
elseif D<0
D = 0;
end
VAprev = VA;
PAprev = PA;
Dprev = D;
end
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!