If a=[1 2 3], b=[10 20 30], how to create c=[10 20 20 30 30 30]?
1 次查看(过去 30 天)
显示 更早的评论
The b matrix i'th element is repeated the number of times the given number in 'a' matrix and placed in matix 'c'. Also if a=[0 1 2], b=[10 20 30] how to get c=[20 30 30]??
0 个评论
采纳的回答
更多回答(2 个)
Roger Stafford
2014-7-14
编辑:Roger Stafford
2014-7-14
Another way:
t = accumarray(cumsum([1,a]).',1);
c = b(cumsum(t(1:end-1)));
2 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String Parsing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!