Function that returns an NxN matrix

3 visualizaciones (últimos 30 días)
Michael
Michael el 8 de Oct. de 2014
Comentada: Andrei Bobrov el 10 de Oct. de 2014
I need to create a function that when a value for N is entered it returns an NxN identity matrix. But this needs to be done without employing Matlab commands which operate on entire matrices, rows, and columns.
  2 comentarios
Andrei Bobrov
Andrei Bobrov el 8 de Oct. de 2014
in MATLAB without employing Matlab commands - how?
Stephen23
Stephen23 el 8 de Oct. de 2014
All functions require MATLAB commands, starting with the function function.

Iniciar sesión para comentar.

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 8 de Oct. de 2014
for jj = N:-1:1
out(jj,jj) = 1;
end
  5 comentarios
Stephen23
Stephen23 el 9 de Oct. de 2014
Editada: Stephen23 el 9 de Oct. de 2014
Andrei Bobrov: I like the array preallocation through the reversed sequence. That is a nice touch!
Andrei Bobrov
Andrei Bobrov el 10 de Oct. de 2014
Hi Stephen! This is idea by Jan Simon.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by