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

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

 Réponse acceptée

Hernia Baby
Hernia Baby le 4 Juil 2021

2 votes

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 commentaire

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Produits

Version

R2020b

Community Treasure Hunt

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

Start Hunting!