필터 지우기
필터 지우기

Create intermediate indices from vectors of start and stop indices?

조회 수: 3 (최근 30일)
Donald
Donald 2012년 2월 20일
Is there a fast way to create a vector of indices taking as an input two vectors containing the start and stop indices?
I want:
a = [2 7 9 17]; b = [4 7 12 17];
c = fun(a,b) = [2 3 4 7 9 10 11 12 17];
  댓글 수: 1
Image Analyst
Image Analyst 2012년 2월 21일
I guess I'm not following. Which of the 4 elements of a, or the 4 elements of b, or the 9 elements of c represent the start indices, and which represent the stop indices?

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

채택된 답변

Jan
Jan 2012년 2월 20일
See Bruno's FEX: mcolon.
Are the values always integers? Can the intervals overlap? These details are very important for the implementation.
[EDITED] If the intervals do not touch eachother - in other words: if there is always an element between them:
a = [2 7 9 17];
b = [4 7 12 17];
k(b+1) = -1;
k(a) = 1;
c = find(cumsum(k));
For large arrays it would help to save time, if CUMSUM handle INT8 vectors - unfortunately it doesn't.
  댓글 수: 3
Jan
Jan 2012년 2월 21일
Can the intervals "touch" eachother. e.g. [1 4] [3 6]?
Donald
Donald 2012년 2월 21일
The intervals cannot touch each other so your answer is pretty much what I'm looking for.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by