how to create series of indices from vectors of numbers
4 次查看(过去 30 天)
显示 更早的评论
Sorry for the obscure title, I think if i show an example it will be easy to understand. I have a vector of numbers: myvec = [ 1 45 70 ]; and I want to somehow generate a set of indices like this:
output = [1 2 3 4 5 6 7 8 9 10 11 45 46 47 48 49 50 51 52 53 54 55 70 71 72 73 74 75 76 77 78 79 80 ]
if i wrote a for loop, it would look like this:
for( i = 1:length(myvec) ) output = [output myvec(i):myvec(i)+10]; end
is there a simple, vectorized way to do this in matlab? for loops are terribly slow, and I want my code to be as fast as possible. thanks!
Liz
0 个评论
采纳的回答
Wayne King
2011-11-22
Hi, one way:
input = [1 45 70];
y = arrayfun(@(x) x:x+10,input,'uni',0);
y = cell2mat(y);
3 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Title 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!