MATLAB: Occur “Index out of range” when run a “for” loop

index out of range

Hi, I have a problem when run a "for" loop. there always hints " Try to access x(:,73); becasue of size(x)=[1,6],index is out of range", " Error EnergConsum (line 19)". Code is shown in following:
L=length(Ed); % length(Ed)=24;
for t=1:L
a=3*(t-1)+1; % x=[(Re, Rb, Ra)_1,...(Re, Rb, Ra)_t,...(Re, Rb, Ra)_L,(Enratedr,Qbratedr,Qaratedr)], 1*(3L+3) Array;
b=3*(t-1)+2;
c=3*(t-1)+3;
Eenr(t)=x(:,a).*x(:,3*L+1); % Line19
Re=x(:,a),Enratedr=x(:,3*L+1);
EFenomr=0.35;
EFen(t)=EFenomr*(0.1904+0.024*x(:,a)-0.0001591*x(:,a).^2);
EFloss=0.08;
Fer(t)=Eenr(t)./EFen(t);
Qwasr(t)=Fer(t).*(1-EFen(t)-EFloss);
...
end

Best Answer

x has the size [1 x 6]. The code try to access x(:, 73) here:
Eenr(t) = x(:, a) .* x(:, 3*L+1);
If L=24, this is an expected error. We cannot guess how this must be fixed.