Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to efficiently replace a vector of ids by a vector of corresponding numerical values

Tags:

matlab

Assuming a vector (or matrix) of ids

>  1 2 3 3 2

Let's suppose each of these ids corresponds to a numerical value, stored in another vector

14 33 25

I'd like to replace the ids by their corresponding value to build the following vector

14 33 25 25 33

There must be a simple way to achieve this without resorting to loops, but my brain fails me at the moment, and I couldn't find anything in the documentation. Any ideas?

like image 533
Kena Avatar asked Jan 24 '26 02:01

Kena


1 Answers

assuming:

x = [14 33 25]

ind = [1 2 3 3 2]

then

x(ind) = 14 33 25 25 33
like image 191
Nathan Fellman Avatar answered Jan 25 '26 23:01

Nathan Fellman