Elegant / Vectorized way of getting array from start_index vector and end_index vector?
1 次查看(过去 30 天)
显示 更早的评论
Hello
Suppose start_index = [1 5 10]; and end_index = [3 8 12];
Is there an elegant solution to get an output of [1 2 3 5 6 7 8 10 11 12], that is the function takes each start value and gives all inclusive values between the start and end value, repeats with the next index, until all inclusive values are included in a single output vector?
Thank you
0 个评论
采纳的回答
Azzi Abdelmalek
2013-3-16
编辑:Azzi Abdelmalek
2013-3-16
EDIT
v=[1 2 3 5 6 7 8 10 11 12]
start_index = [1 5 10];
end_index = [3 8 12];
out=cell2mat(arrayfun(@(x,y) x:y,start_index, end_index,'un',0))
out=intersect(out,v)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!