MATLAB Answers

0

matrix generation 1 to n*n or interval

Gohaku 님이 질문을 제출함. 18 Mar 2014
최근 활동 Jos (10584) 님이 댓글을 추가함. 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

로그인 to comment.

답변 수: 2

Jos (10584) 님의 답변 18 Mar 2014
 채택된 답변

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

  댓글 수: 2

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

로그인 to comment.


Thomas 님의 답변 18 Mar 2014
Thomas 님이 편집함. 18 Mar 2014

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

  댓글 수: 0

로그인 to comment.



Translated by