How do I make a 10x10 showing all numbers 1 to 100?
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Stephen23
el 31 de Mayo de 2021
@Patrick Duffy: what have you tried so far? Is it a strict requirement to use nested loops?
Respuestas (1)
Animesh
el 5 de Mayo de 2025
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 comentario
Adam Danz
el 5 de Mayo de 2025
An alternative that uses implicit expansion:
M = (1:10) + (0:10:90)'
Generalized for an n-by-n matrix with values 1:n^2:
n = 8;
M = (1:n) + (0:n:n^2-n)'
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!