Creating an array from 1 to n
조회 수: 919 (최근 30일)
이전 댓글 표시
Hello!
I am trying to create an array of integers from 1 to n [1 2 3 ..... n], where n is a variable that can change.
How should I approach that?
Thank you!
댓글 수: 3
Luis Benitez Prieto
2021년 7월 27일
It is elemantary but also not. If you look at the accepted answer below. The answer is creating a double array, the numbers inside are integer values, but not of interger format.
I actually was interested in this question because when I want to create an array of integers I do not want to create a double array in the process by doing something like:
uint32([1:10])
Instead, I would like to directly create an integer array. And thats something I have not easily found in the documentation and a legit question in my opinion. Perhaps thats what the poster is asking for.
Stephen23
2021년 7월 27일
편집: Stephen23
2021년 7월 27일
@Luis Benitez Prieto: like this:
V = uint32(1):uint32(10)
class(V)
Note that just one uint32 input is sufficient to define the output as uint32:
class(uint32(1):10)
class(1:uint32(10))
Note that the square brackets in your example are superfluous and misleading:
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!