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?

 Akzeptierte Antwort

Matt Fig
Matt Fig am 15 Mai 2011

0 Stimmen

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

2 Kommentare

Oleg Komarov
Oleg Komarov am 15 Mai 2011
too fast!
Matman86 Di
Matman86 Di am 16 Mai 2011
Thanks much! ^-^

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by