"Undefined function or variable 'PA'. The first assignment to a local variable determines its class.". Why do I keep getting this error?
Afficher commentaires plus anciens
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;
Réponses (1)
Walter Roberson
le 3 Août 2022
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 commentaires
Ali Zubair
le 3 Août 2022
Walter Roberson
le 4 Août 2022
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
Catégories
En savoir plus sur Solar Power dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!