Sorting an array and their corresponding

1 visualización (últimos 30 días)
Ko Fa
Ko Fa el 28 de Jul. de 2020
Respondida: KSSV el 28 de Jul. de 2020
kinda stupid question but I couldnt figure it out,
I have two arrays, say
a = [5;10;1]
b = [0.1;0.2;0.3]
Now I am trying to sort the first array using sort and I want the corresping elements in array b sort with their corresponding element in a them, so if I do
sort(a)
I want the output to be
a = [1;5;10]
b = [0.3;0.1;0.2]
The corresponding elements in element b should stick with their original elemnt in a.
Any help is greatly appreciated.

Respuesta aceptada

KSSV
KSSV el 28 de Jul. de 2020
[val,idx] =sort(a) ;
iwant = b(idx) ;

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by