# What wrong with my code? anyone can help?

2 views (last 30 days)
Shahid Said on 22 Nov 2021
Answered: Benjamin on 23 Nov 2021
Hello sir.
This is my code
SDR = 0.11
Cx=184
Pmp_stc = PV_module(10,2)
Vbatt = Battery(1,1)
Ebatt_min = (1-DODMax).*(Cbatt.*Battery(1,1))
Ebatt_max=Cx*Vbatt
Ebatt=Ebatt_max
for n =1:16992
if n==1
Ebatt_cal=Ebatt_min
LPS=0
SOC=Ebatt_cal/(Cx*Vbatt)
else
if Ebatt(n-1)<Ebatt_max
LPS=0
if Ebatt_cal>Ebatt_max
Ebatt_cal=Ebatt_max
else
Ebatt_cal=Ebatt_cal
end
SOC=Ebatt_cal/(Cx*Vbatt)
else
if Ebatt_cal<Ebatt_min
Ebatt_cal=Ebatt_min
else
Ebatt_cal=Ebatt_cal
end
if LPS<=0
LPS=0
else
LPS=LPS;
end
SOC=Ebatt_cal/(Cx*Vbatt)
end
else
Ebatt(n-1)>=Ebatt_max
Esys=0
if Ebatt_cal<Ebatt_min
Ebatt_cal=Ebatt_min
else
Ebatt_cal=Ebatt_cal
end
if LPS<=0
LPS=0
else
LPS=LPS
end
SOC=Ebatt_cal/(Cx*Vbatt)
end
end
Jawapan=[Ebatt_cal SOC LPS]
if n==l
Jawapan1=Jawapan;
else
Jawapan1=[Jawapan1;Jawapan]
end
Ebatt=Jawapan1(:,1);
LPSrec=sum(Jawapan(:,3));
end
SOCcur=-Jawapan1(:,2);
if barisa==1
SOCall=SOCcur;
else
SOCall=[SOCall SOCcur];
end
LPSP=LPSrec/((Eac1*66)+(Eac2*26))
matlab show error
Undefined function or variable 'l'.
Error in CASE1_LPSP (line 105)
if n==l
i already check all the line but did not find the problem.pls help.
anyone can show me the the simpler code or better way to code this ? thank you so much.

Benjamin on 23 Nov 2021
That line is "if n == l" with a lower-case L, which is not a defined variable, evidently. Maybe it should be "if n == 1", with the number one (1).

R2018a

### Community Treasure Hunt

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

Start Hunting!