필터 지우기
필터 지우기

List of increasing integers

조회 수: 4 (최근 30일)
Tony Haines
Tony Haines 2024년 2월 22일
댓글: Dyuman Joshi 2024년 2월 22일
I have a list of dimensions given by the row vector as follows
I would like to associate with this vector, a list of increasing integers such that each size in 'dim' corresponds with an exact number of integers like this:
int = [ 1 2 , 3 4, 5 6 7 8, 9 10, 11 12, 13 14, 15 16, 17 18, 19 20, 21 22, 23 24, 25 26]
I grouped the integers just to indicate that a dim=4 corresponds to 5 6 7 8. and the rest just has two integers.
Thanks.

채택된 답변

Dyuman Joshi
Dyuman Joshi 2024년 2월 22일
dim = [2 2 4 2 2 2 2 2 2 2 2 2]
dim = 1×12
2 2 4 2 2 2 2 2 2 2 2 2
int = 1:sum(dim)
int = 1×26
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
out = mat2cell(int, 1, dim)
ans = 1×12 cell array
{[1 2]} {[3 4]} {[5 6 7 8]} {[9 10]} {[11 12]} {[13 14]} {[15 16]} {[17 18]} {[19 20]} {[21 22]} {[23 24]} {[25 26]}
  댓글 수: 2
Tony Haines
Tony Haines 2024년 2월 22일
This is what I needed. To have it all in a cell. Thank you!
Dyuman Joshi
Dyuman Joshi 2024년 2월 22일
You're welcome!

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

추가 답변 (1개)

Les Beckham
Les Beckham 2024년 2월 22일
Are you sure that is what you want? It doesn't seem very useful.
dim = [2 2 4 2 2 2 2 2 2 2 2 2]
dim = 1×12
2 2 4 2 2 2 2 2 2 2 2 2
int = 1:sum(dim)
int = 1×26
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
int(end)
ans = 26
  댓글 수: 1
Tony Haines
Tony Haines 2024년 2월 22일
Thank you very much. It's very useful for what i'm working on.

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

카테고리

Help CenterFile Exchange에서 Elementary Math에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by