MATLAB: For Loop /Array question

for loophomework

How would i go about creating a for loop to create an array where each value in X is equal to its associated row value * 2 plus its associated column value * 3 +1. Size of array is 50×50 ?

Best Answer

How about this?:
X = zeros(50, 50);
[m, n] = size(X); % m x n = 50, 50
for i = 1:m % Row
for j = 1:n % Column
X(i, j) = i * 2 + j * 3 + 1;
end
end
(m, n) could be anytihng.
The point here is size function. Good luck!