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

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

Accepted Answer

Hernia Baby
Hernia Baby on 4 Jul 2021
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 Comment
Gamma1990
Gamma1990 on 4 Jul 2021
ご回答ありがとうございます.大変参考になりました.

Sign in to comment.

More Answers (0)

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!