matrix generation 1 to n*n or interval

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.

 Akzeptierte Antwort

Jos (10584)
Jos (10584) am 18 Mär. 2014

1 Stimme

reshape(1:n^2,n,n).'

2 Kommentare

Gohaku
Gohaku am 18 Mär. 2014
Thank you guys both answers were good
You might also take a look at this function which I submitted over 8 years ago on the File Exchange:
out = slm(n).'

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Thomas
Thomas am 18 Mär. 2014
Bearbeitet: Thomas am 18 Mär. 2014

2 Stimmen

n=10;
a=1:n*n;
out=reshape(a,n,n)'

Kategorien

Mehr zu MATLAB Coder finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 18 Mär. 2014

Kommentiert:

am 18 Mär. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by