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.
  댓글 수: 1
Stephen23
Stephen23 2018년 1월 23일
"from 1 to infinite"
Does your computer have enough memory to store an array with an infinite number of elements?

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

채택된 답변

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);
CodeElinesa
CodeElinesa 2018년 1월 23일
sorry, I misunderstood it. I got this one after your answer. Thank you very much!

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

추가 답변 (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