MATLAB Answers

0

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

Asked by Nate Secinaro on 16 May 2019
Latest activity Answered by David Goodmanson on 17 May 2019
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!

  0 Comments

Sign in to comment.

1 Answer

Answer by David Goodmanson on 17 May 2019
 Accepted Answer

Hi Nate,
c = b(a) gets it done. a becomes an index vector into the elements of b.

  0 Comments

Sign in to comment.