Hey guys! I am still kind of getting a hang of Matlab and I have a quick favor to ask you guys. The question is to create a double for loop for the following 3 × 4 matrix with ijth matrix element: A(i,j)=i+j, 1≤i≤3, 1≤j≤4 Construct this matrix in MATLAB using the following four methods: a. Using a double for-loop. b. Using a for-loop that builds the matrix row by row. c. Using a for-loop that builds the matrix column by column.
I have already done this but I am getting sort of an odd answer, would someone please verify my work?
i=3;j=4;A=zeros(i,j);for k=1:i, for z=1:j A(k,z)=i+j; endendA%Part B
for k=1:i A(k)=i+j;endA%Part C
for z=1:j A(z)=i+j;endA
oh and this are the arrays I got:
A =
7 7 7 7 7 7 7 7 7 7 7 7
A =
7 7 7 7 7 7 7 7 7 7 7 7
A =
7 7 7 7 7 7 7 7 7 7 7 7
Best Answer