matrix generation 1 to n*n or interval

조회 수: 1 (최근 30일)
Gohaku
Gohaku 2014년 3월 18일
댓글: Jos (10584) 2014년 3월 18일
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.

채택된 답변

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

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Thomas
Thomas 2014년 3월 18일
편집: Thomas 2014년 3월 18일
n=10;
a=1:n*n;
out=reshape(a,n,n)'

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by