Create intermediate indices from vectors of start and stop indices?
2 ビュー (過去 30 日間)
古いコメントを表示
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
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
2012 年 2 月 20 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!