Replace vector of idexes with values from another vector corresponding to those indexes
1 次查看(过去 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!
0 个评论
采纳的回答
David Goodmanson
2019-5-17
Hi Nate,
c = b(a) gets it done. a becomes an index vector into the elements of b.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!