Is there a command ( like "sort" for example ) arranges vector elements ascending ,max, descending (humped shap)?

1 Ansicht (letzte 30 Tage)
Is there a command ( like "sort" for example ) arranges vector elements ascending ,max, descending (humped shap)?
  6 Kommentare
Mohammed AlThani
Mohammed AlThani am 28 Okt. 2019
yes, kind of.
but as index increase the value increases too, till maximum ,then the opposit as index increases value decreases. " hump shaped arrangement"

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 28 Okt. 2019
>> V = randi(99,1,23)
V =
93 68 76 74 39 65 17 70 4 28 5 10 82 69 32 95 4 44 38 76 79 19 49
>> Y = sort(V);
>> Z = [Y(1:2:end),fliplr(Y(2:2:end))]
Z =
4 5 17 28 38 44 65 69 74 76 82 95 93 79 76 70 68 49 39 32 19 10 4

Weitere Antworten (1)

Yuan Li
Yuan Li am 28 Okt. 2019
Yes. Use sort.
e.g.
a = [1,3,2,4];
b = sort(a,'ascend');% b = [1,2,3,4]
c = sort(a,'descend');% c = [4,3,2,1]

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by