Order two related vectors

Hi, I have 2 vectors: one numeric vector and a string vector ( a cell array to be exact). String one refers to value one, string two to value two and so on. I want to sort the numeric vector and, according to the result, order the string vector too, for example:
v1 v2 2 "my name is" 1 "hello" 3 "Bob"
after the ordering v1 v2 1 "hello" 2 "my name is" 3 "bob"
How can I accomplish this?

 채택된 답변

Matt Fig
Matt Fig 2011년 5월 15일

0 개 추천

For example:
A = [3 1 4 2];
B = {'Bob' 'Jeff' 'Mike' 'Len'};
[As,I] = sort(A);As
Bs = B(I)

댓글 수: 2

Oleg Komarov
Oleg Komarov 2011년 5월 15일
too fast!
Matman86 Di
Matman86 Di 2011년 5월 16일
Thanks much! ^-^

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

질문:

2011년 5월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by