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?

 Accepted Answer

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

2 Comments

too fast!
Thanks much! ^-^

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!