Replace vector of idexes with values from another vector corresponding to those indexes

2 ビュー (過去 30 日間)
I have:
a = [1 1 2 2 2 3]
b = [9 8 7]
I need :
c = [9 9 8 8 8 7]
I can do this with a loop, but I am looking for a more effecint way. I have a vector that is 1x150000 that I need to do this for.
Thank you!

採用された回答

David Goodmanson
David Goodmanson 2019 年 5 月 17 日
Hi Nate,
c = b(a) gets it done. a becomes an index vector into the elements of b.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by