% A script which shows how an array can grow inside a loop % What most people used...may not be used everywhere. A=[]; for i=1:5 A(i) = i^2; end A % What you should use B=[]; for i=1:5 B = [B i^2]; end B D=[]; for i=1:5 D = [D i^2]; end D E=[]; for i=1:5 temp = [i i^2 i^3 i^4 i^5]; E=[E ; temp]; % adding one more row at each iteration end E G=[]; for i=1:5 temp = [i i^2 i^3; i^4 i^5 i^6]; G=[G ;temp]; % adding two rows at each step end G