replication of elements in a vector
古いコメントを表示
There's a data set
x = [1 2.2 1.5 4 2]
Consider a index vector
indx = [0 0 2 1 2]
The number of copies of each element in 'x' is given in 'indx.' I want a new vector in which the elements of x are arranged according to indx, i.e., the output should be
xnew = [1.5 1.5 4 2 2]
Could you please suggest ways to do this without a for loop?
2 件のコメント
KSSV
2017 年 6 月 12 日
For
idx = [3 3 4 5 5];
You will get what you want
xnew = x(idx) ;
Praveen Choppala
2017 年 6 月 12 日
編集済み: Praveen Choppala
2017 年 6 月 12 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!