-1

I have an array x:

x = [2, 1, 2, 3, 3, 2]

I also have a cell array y:

y = {'alpha', 'beta', 'gamma'}

In fact, x is a list of indices, where each indicates an element in y. I now want to create another cell array z, where each index in x is replaced with the corresponding element in y, to give the following:

z = {'beta', 'alpha', 'beta', 'gamma', 'gamma', 'beta'}

How do I do this?

Amro
  • 123,847
  • 25
  • 243
  • 454
Karnivaurus
  • 22,823
  • 57
  • 147
  • 247

1 Answers1

5

How about this :

z = y(x)

I do not have MatLab on my computer right now, but I think that should work.

Sifu
  • 1,082
  • 8
  • 26