Ordenar vector en función de otro vector

조회 수: 7 (최근 30일)
Paúl Llerena
Paúl Llerena 2020년 4월 25일
답변: Deepak Gupta 2020년 4월 25일
Hola comunidad de Matlab, tengo una duda,
Tengo un vector a=[1,3,5,7,9,12,2] y un vector b=['b','a','f','z','j','e','m'].
Quiero trabajar con estos dos vectores de manera que si ordeno el vector 'a' en forma descendente, también se me ordene el vector b. Es decir con las posiciones ordenadas de a, ordenar b. Por ejemplo con los vectores anteriores:
a_ordenado=[1,2,3,5,7,9,12]
b_ordenado=['b','m','a','f','z','j','e']
Espero que alguien me pueda ayudar. ¡Gracias!

답변 (1개)

Deepak Gupta
Deepak Gupta 2020년 4월 25일
Hi,
You can save both arrays a and b in another 2 dimentional array and then short this 2D array according to your array a then extract the required result.
Thanks

카테고리

Help CenterFile Exchange에서 FPGA, ASIC, and SoC Development에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by