If a=[1 2 3], b=[10 20 30], how to create c=[10 20 20 30 30 30]?
5 ビュー (過去 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!