Array Aをソートしそれに合わせArray Bの順序を入れ換える

A = [2 4 5], B = [1.2 0.7 0.1]と与えられた2つのarrayが有ります。
Bは有る関数を元に、Aから生成された値です。
Bを昇順にsortし(結果[0.1 0.7 1.2]となる)、それに合わせarray-A要素順序を並び替える為の手順(code)を教えて下さい。
Aの並びは、[5 4 2]となるMatlabのcoding手法をお伺いしています。

 Respuesta aceptada

Kazuya
Kazuya el 5 de En. de 2019

0 votos

[B,I] = sort(___)
の構文で出力できる I を使えばOKです。
参照:sort 関数のヘルプページ https://jp.mathworks.com/help/matlab/ref/sort.html
A = [2 4 5];
B = [1.2 0.7 0.1];
[~,I] = sort(B);
A(I)
ans =
5 4 2

2 comentarios

Takashi KOSHIMIZU
Takashi KOSHIMIZU el 6 de En. de 2019
回答の投稿有難うございます。非常に参考になりました。
~の意味合いも理解させて頂きました。
Kazuya
Kazuya el 7 de En. de 2019
よかったです。sortrows 関数だと、行列や table 変数を特定の列のデータをもとに、マルっとソートできるので、より便利かもしれません。

Iniciar sesión para comentar.

Más respuestas (1)

madhan ravi
madhan ravi el 5 de En. de 2019

0 votos

sort(A,'descend')
sort(B,'descend')

Categorías

Más información sobre 行列および配列 en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 5 de En. de 2019

Comentada:

el 7 de En. de 2019

Community Treasure Hunt

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

Start Hunting!