Replace vector of idexes with values from another vector corresponding to those indexes
조회 수: 3 (최근 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!