I'm trying to simulate a battery connected to a PV system. However, there seems to be an issue with column vector since I get this error message: In an assignment A(I) = B, the number of elements in B and I must be the same at line 30 (BatteriLaddning(i)=diff(i)). I guess the issue is not limited to that line, but the first value ends up there and therefore the error occurs there. Here's my code:
Data=importdata('BatteriData.txt');Produktion=zeros(8760,1);Konsumtion=zeros(8760,0);Diff=zeros(8760,0);BatteriLaddning=zeros(8760,1); Overskott=zeros(8760,1);Produktion=Data(:,1); %ta ut första kolumnen
Konsumtion=Data(:,2); %ta ut andra kolumnen
Diff=Data(:,3); %ta ut tredje kolumnen
AntalBatterier=2;BatteriKapacitet=7*AntalBatterier;EffektKapacitet=2*AntalBatterier;OverskottH=0;%Läs in de tre första från extern fil
for i=1:8760 if (diff(i)>0&BatteriLaddning(i)>=BatteriKapacitet) Overskott(i)=diff(i); OverskottH=OverskottH+1; elseif (diff(i)<0&diff(i)>EffektKapacitet) Overskott(i+1)=diff(i)-EffektKapacitet; OverskottH=OverskottH+1; if (i==1) BatteriLaddning(i)=EffektKapacitet; else BatteriLaddning(i)=BatteriLaddning(i-1)+EffektKapacitet; end else if(i==1) BatteriLaddning(i)=diff(i); else BatteriLaddning(i)=BatteriLaddning(i-1)+diff(i); end endend
Best Answer