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

3 vues (au cours des 30 derniers jours)
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!

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by