列ベクトルの成分を上​から大きい順に変える​ことはできますか?

列ベクトルが下のようなときについて質問です.
A=
1
2
3
2
このとき,行列Aの成分を上から大きい順に入れ替えた行列Bに変換して,
B=
3
2
2
1
としたいのですが,どのように実装すればよいのでしょうか?
よろしくお願いします.

 Risposta accettata

Hernia Baby
Hernia Baby il 4 Lug 2021

2 voti

sortの'descend'オプションで解決します。
a = [1 2 2 3]
a = 1×4
1 2 2 3
b = sort(a,'descend')
b = 1×4
3 2 2 1

1 Commento

Gamma1990
Gamma1990 il 4 Lug 2021
ご回答ありがとうございます.大変参考になりました.

Accedi per commentare.

Più risposte (0)

Prodotti

Release

R2020b

Community Treasure Hunt

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

Start Hunting!