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

15 ビュー (過去 30 日間)
Patrick Duffy
Patrick Duffy 2021 年 1 月 13 日
コメント済み: Adam Danz 2021 年 6 月 1 日
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 件)

Kunal Kandhari
Kunal Kandhari 2021 年 6 月 1 日
Following code will create a matrix as stated above:
x=reshape( 1:100, 10, 10).';
%1:100 will create a linear matrix with 1 to 100 as elements
% reshape will convert the 1 to 100 matrix into 10*10 form
% .' will do transpose of it
X will contain the required result
You can see more detailed description of used functions here:
Reshape:
Transpose:
https://in.mathworks.com/help/matlab/ref/transpose.html
  1 件のコメント
Adam Danz
Adam Danz 2021 年 6 月 1 日
175 times faster using implicit expansion
y = (1:10:100)'+(0:9);
Each point below is the runtime of 10000 iterations using the reshape method (red) and the implicit expansion method (blue) which was repeated 50 times (x-axis).
  • reshape mean: 0.0151 sec (10000 iterations)
  • implicit expansion mean: 8.6220e-05 sec (10000 iterations)

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by