# Can someone help me Create a function called that will automatically generate an array where the elements in the array are the sum of the indices? i am lost on this.

2 ビュー (過去 30 日間)
John Nowak 2019 年 9 月 27 日
Commented: John Nowak 2019 年 9 月 28 日
% Im not even sure if I am on the right path here but here is what i have started... any help would be greatly appreciated!!
m = magic(m)
n = magic(n)
A = ?
end

#### 1 件のコメント

darova 2019 年 9 月 27 日
Can you please provide some example? How output should looks like?

サインイン to comment.

### 採用された回答

James Tursa 2019 年 9 月 27 日

If I understand your description correctly, the magic( ) function has nothing to do with your assignment. You are simply asked to construct an m x n matrix where the (i,j) element has the value i+j. That's it, nothing else. So an outline:
A = ____; % <- you fill in the blank to create a matrix of size m x n
_____; % <-- you put code here to set A(i,j) to i+j for all the elements of A
end
Fill in the blanks above.
To create the matrix, you could e.g. use the zeros( ) function.
For the i+j stuff, you could use two nested for-loops over the elements of A, or you could use vectorized code, etc.

#### 4 件のコメント

James Tursa 2019 年 9 月 27 日
Yes, that matches my guess. So follow my instructions. E.g., A(1,1) = 1+1 = 2, and A(12,13) = 12+13 = 25 matches what I thought the assignment was.
John Nowak 2019 年 9 月 27 日
thank you!
John Nowak 2019 年 9 月 28 日
okay so I am still lost with this. is there any chance you can try and give me another clue as to put this together?

サインイン to comment.

サインイン してこの質問に回答します。

Translated by