How do I create a (10,10) matrix containing numbers from 1 to 100?

How do I create a (10,10) matrix containing numbers from 1 to 100?
I just want the numbers to go 1 to 10 on the top row, then 11-20 on the 2nd row etc.

2 件のコメント

James Tursa
James Tursa 2013 年 9 月 18 日
Is this homework? What have you tried so far?
Tom
Tom 2013 年 9 月 18 日
I did it using
ij = [1:10 ; 11:20 ; 21:30 ; 31:40 ; 41:50 ; 51:60 ; 61:70 ; 71:80 ; 81:90 ; 91:100]
but Walter's is better obviously. I'm just getting going on my Master's dissertation in Audio Acoustics.

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2013 年 9 月 18 日

3 投票

reshape( 1:100, 10, 10) .'

2 件のコメント

Tom
Tom 2013 年 9 月 18 日
Many thanks Walter!
Sudeepta  Banerjee
Sudeepta Banerjee 2022 年 1 月 25 日
Thank you Man

サインインしてコメントする。

その他の回答 (4 件)

Steven Lord
Steven Lord 2022 年 1 月 25 日
Another solution using implicit expansion (which wasn't available back in 2013 when this question was posted):
n = 10;
A = (1:n) + n*(0:n-1).'
A = 10×10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
SYED ABOU ILTAF HUSSAIN
SYED ABOU ILTAF HUSSAIN 2018 年 9 月 2 日
編集済み: SYED ABOU ILTAF HUSSAIN 2018 年 9 月 2 日

1 投票

Try this a= [1:10]; for i=2:10 a(i,:)=a(i-1,:)+10; end
DGM
DGM 2022 年 1 月 25 日
編集済み: DGM 2022 年 1 月 25 日
If we're posting solutions which are instructive, even if not ideal:
A = zeros(10);
A(:) = 1:100;
A = A.'
A = 10×10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
finess
finess 2022 年 8 月 26 日

0 投票

create a new 4x4 matrix that is filled with the number 100

9 件のコメント

Stephen23
Stephen23 2022 年 8 月 26 日
"create a new 4x4 matrix that is filled with the number 100"
What did you try so far?
finess
finess 2022 年 8 月 27 日
I tried to make a matrix A that would print the number 100 a hundred times but It didn't really work well! I am not sure why
A(:)=100
that was it
A = zeros(4,4);
A(:) = 100
A = 4×4
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
finess
finess 2022 年 8 月 27 日
thanks mhn roberson !
Appreciate that ! would you guys recommend some resources to check out the basics of programming in matlab ! I want learn how to figure out problems in matlab but it keeps puzzling me
finess
finess 2022 年 8 月 27 日
but again why is the answer the way it is ?
Les Beckham
Les Beckham 2022 年 8 月 27 日
I recommend using this free Matlab training course (link below):
Walter Roberson
Walter Roberson 2022 年 8 月 27 日
編集済み: Walter Roberson 2022 年 8 月 27 日
There are a number of different ways to achieve the same result.
A = 100 + zeros(4,4)
A = 4×4
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
A = 100 * ones(4,4)
A = 4×4
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
A = 100; A = A(ones(4,4))
A = 4×4
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
A = zeros(4,4); A(:) = 100
A = 4×4
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
A(1:4,1:4) = 100
A = 4×4
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
A = repmat(100,4,4)
A = 4×4
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
finess
finess 2022 年 8 月 28 日
Wow I love these Answers! It gives me a feeling of how a great teacher looks like, with great options for students
DGM
DGM 2024 年 5 月 13 日
Flagged by 博文 on 23 Apr 2024:
GOOD

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

タグ

質問済み:

Tom
2013 年 9 月 18 日

コメント済み:

DGM
2024 年 5 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by