MATLAB: How solve index exceed matrix dimension?

%A CREATES A RANDOM MATRIX OF MAXIMUM INTERGER OF 10
rng('default');
A = randi(10, 20, 1);% A randi is a 20×20 matrix selected from discrete uniform integers whose range is from 1 to 10
B = [];%ELEMENTS ARE INSERTED IN B
for i = 1:20 %the elements ranges from 1 to 20 B = [B, A]; A = circshift(A, 2); end
disp(B)
I= eye(20) %COL 1
I(1,:)=1/9*I(1,:) I(2,:)=I(2,:)-10*I(1,:) I(3,:)=I(3,:)-2*I(1,:) I(4,:)=I(4,:)-10*I(1,:) I(5,:)=I(5,:)-7*I(1,:) I(6,:)=I(6,:)-I(1,:) I(7,:)=I(7,:)-3*I(1,:) I(8,:)=I(8,:)-6*I(1,:) I(9,:)=I(9,:)-10*I(1,:) I(10,:)=I(10,:)-10*I(1,:) I(11,:)=I(11,:)-2*I(1,:) I(12,:)=I(12,:)-10*I(1,:) I(13,:)=I(13,:)-10*I(1,:) I(14,:)=I(14,:)-5*I(1,:) I(15,:)=I(15,:)-9*I(1,:) I(16,:)=I(16,:)-2*I(1,:) I(17,:)=I(17,:)-5*I(1,:) I(18,:)=I(18,:)-10*I(1,:) I(19,:)=I(19,:)-8*I(1,:) I(20,:)=I(20,:)-10*I(1,:)
%COL 2
I(1,:)= I(1,:)- I(2,:) I(3,:)=1/7*I(3,:)-I(2,:) I(4,:)=I(4,:)-I(2,:) I(5,:)=-I(5,:)-4*I(2,:) I(6,:)=1/9*I(6,:)-I(2,:) I(7,:)=I(7,:)-4*I(2,:) I(8,:)=-I(8,:)-4*I(2,:) I(9,:)=-1/6*I(9,:)-I(2,:) I(10,:)=-I(10,:)-3*I(2,:) I(11,:)=-1/8*I(11,:)+I(2,:) I(12,:)=I(12,:)-I(2,:) I(13,:)=-1/7*I(13,:)-I(2,:) I(14,:)=-1/6*I(14,:)+I(2,:) I(15,:)=I(15,:)-2*I(2,:) I(16,:)=I(16,:)-3*I(2,:) I(17,:)=1/5*I(17,:)-I(2,:) I(18,:)=-1/7*I(18,:)-I(2,:) I(19,:)=-I(19,:)-2*I(2,:) I(20,:)=I(20,:)-I(2,:)
augB= [I B]
C= I*augB
D=round(C )

Best Answer

On my computer the code runs fine. Perhaps you have redefined a builtin function like eye, disp, circshift or round as a variable? If you post the complete error message, such problems would become clear.
Insert the code in a function to avoid such mistakes. And do not redefine built-in functions as variables. This is no error, but causes unexpected troubles frequently. When you use functions instead of scripts or code in the command window, you can at least see in the code, when such a redefinition is done.