MATLAB Answers

Gohaku
0

matrix generation 1 to n*n or interval

Asked by Gohaku
on 18 Mar 2014
Latest activity Commented on by Jos (10584)
on 18 Mar 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.

  0 Comments

Sign in to comment.

2 Answers

Answer by Jos (10584)
on 18 Mar 2014
 Accepted Answer

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

  2 Comments

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).'

Sign in to comment.


Answer by Thomas
on 18 Mar 2014
Edited by Thomas
on 18 Mar 2014

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

  0 Comments

Sign in to comment.