how can I create a new array with same data as existing array and in specific order ?

i have two arrays.
a = [1,2,3,4,5];
b = [6,1,7,3,5];
I want to be able to create another array called 'c' which contains everything a has but in the order it appears in 'b'. so c should look like: -
c = [1,3,5];

 채택된 답변

This works in the more general situation:
a = randi(10, 1, 5);
b = randi(10, 1, 5);
[C,ia,ib] = intersect(a,b);
c = b(sort(ib))

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB Coder에 대해 자세히 알아보기

태그

질문:

ME
2015년 4월 15일

답변:

2015년 4월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by