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.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
John Nowak
el 27 de Sept. de 2019
Comentada: John Nowak
el 28 de Sept. de 2019
% 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!!
function A = MagicArrayAdd(m,n)
m = magic(m)
n = magic(n)
A = ?
end
1 comentario
Respuesta aceptada
James Tursa
el 27 de Sept. de 2019
Editada: James Tursa
el 27 de Sept. de 2019
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:
function A = MagicArrayAdd(m,n)
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!