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 Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by