Define vector that assigns element positions in VecB, corresponding to values in VecA, when length(Vec​A)>length(​VecB)?

조회 수: 1 (최근 30일)
I have an array
VecA=[0 1 0 -1 0 1 -2]
and the vector
VecB= [-2 -1 0 1 2]
I want to creat a vector of length=7, which contains the positiions of each of the elements from VecA in VecB, namely
VecC=[3 4 3 2 3 4 1]
How do I do this using vector operations (no loops)? Is it a one-liner?
Thanks!

채택된 답변

madhan ravi
madhan ravi 2019년 3월 7일
[~,VecC]=ismember(VecA,VecB)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by