MATLAB: Using for loops to generate an array

arraysfor looploopsmatrix manipulation

I need to generate the array A = 1 2 3 4 5; 2 4 6 8 10; 3 6 9 12 15; 4 8 12 16 20; 5 10 15 20 25; using for loops. Don't have much experience with looping, and currently trying to understand it until it clicks. Help!

Best Answer

m = 7; n = 6;
A = zeros(m,n);
for i=1:m
A(i,:) = i:i:i*n;
end
This should work for any size array with rows m and columns n.