matrix generation 1 to n*n or interval

1 visualización (últimos 30 días)
Gohaku
Gohaku el 18 de Mzo. de 2014
Comentada: Jos (10584) el 18 de Mzo. de 2014
hi guys i have a problem.. how can i generate a matrix n*n with 1 to n*n elements or any other interval? like for a 3x3 1 2 3 ; 4 5 6 ; 7 8 9 ( i don't want to type it directly i want to generate it knowing n ). Thank you.

Respuesta aceptada

Jos (10584)
Jos (10584) el 18 de Mzo. de 2014
reshape(1:n^2,n,n).'
  2 comentarios
Gohaku
Gohaku el 18 de Mzo. de 2014
Thank you guys both answers were good
Jos (10584)
Jos (10584) el 18 de Mzo. de 2014
You might also take a look at this function which I submitted over 8 years ago on the File Exchange:
out = slm(n).'

Iniciar sesión para comentar.

Más respuestas (1)

Thomas
Thomas el 18 de Mzo. de 2014
Editada: Thomas el 18 de Mzo. de 2014
n=10;
a=1:n*n;
out=reshape(a,n,n)'

Categorías

Más información sobre Multidimensional Arrays 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