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?

 Respuesta aceptada

Matt Fig
Matt Fig el 15 de Mayo de 2011

0 votos

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

2 comentarios

Oleg Komarov
Oleg Komarov el 15 de Mayo de 2011
too fast!
Matman86 Di
Matman86 Di el 16 de Mayo de 2011
Thanks much! ^-^

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 15 de Mayo de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by