How to create a function of matrix with integer(from 1 to infinite) that can be arranged by row and column

1 次查看(过去 30 天)
for example, if m=2, n=3 then the matrix become [1 2,3 4,5,6]' if m=4 n=4 it is [1 2 3 4,5 6 7 8,9 10 11 12,13 14 15 16]' I know I should use loop, but where should I start it? i think i may need some help here...it asks one output and two inputs.

采纳的回答

Stephen23
Stephen23 2018-1-23
编辑:Stephen23 2018-1-23
Depending on the orientation you are after, either:
reshape(1:m*n,m,n)
or
reshape(1:m*n,n,m).'
  3 个评论
Stephen23
Stephen23 2018-1-23
编辑:Stephen23 2018-1-23
What integer? Your question shows two integers, m and n, both of which occur in my answer. You did not mention any other integers.
Note that you can easily put that code into an anonymous function, e.g.:
fun = @(m,n) reshape(1:m*n,m,n);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by