How do I make a 10x10 showing all numbers 1 to 100?

조회 수: 13 (최근 30일)
Patrick Duffy
Patrick Duffy 2021년 1월 13일
댓글: Adam Danz 2025년 5월 5일
how do i create a nested loop tht will provide me with a 10x10 matrix with all the numbers 1 to 100 like this
1 2 ... 10
11 ... ... ...
... ... ... ...
... ... ... 100
  댓글 수: 1
Stephen23
Stephen23 2021년 5월 31일
@Patrick Duffy: what have you tried so far? Is it a strict requirement to use nested loops?

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

답변 (1개)

Animesh
Animesh 2025년 5월 5일
Following code will create a matrix as stated above:
x=reshape( 1:100, 10, 10).';
'X' will contain the required result
You can see more detailed description of used functions here:
Transpose: https://www.mathworks.com/help/matlab/ref/transpose.html
  댓글 수: 1
Adam Danz
Adam Danz 2025년 5월 5일
An alternative that uses implicit expansion:
M = (1:10) + (0:10:90)'
M = 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
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Generalized for an n-by-n matrix with values 1:n^2:
n = 8;
M = (1:n) + (0:n:n^2-n)'
M = 8×8
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
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by