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

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

6 件のコメント

Bob Thompson
Bob Thompson 2019 年 10 月 28 日
Why does sort not work for you? Are you looking for something more like rowsort?
Adam
Adam 2019 年 10 月 28 日
'ascending, max, descending' is not uniquely defined for a vector of values. Can you give an example of what kind of logic you expect such a function to use?
Mohammed AlThani
Mohammed AlThani 2019 年 10 月 28 日
for example
a = [2 5 4 1 3]
I want to arrange it like
a = [1 3 5 4 2]
Adam
Adam 2019 年 10 月 28 日
編集済み: Adam 2019 年 10 月 28 日
based on what logic though? If I had to guess I'd say you want values sorted alternating at the start and end, with the max in the middle (assuming an odd number of elements).
Mohammed AlThani
Mohammed AlThani 2019 年 10 月 28 日
yes, kind of.
but as index increase the value increases too, till maximum ,then the opposit as index increases value decreases. " hump shaped arrangement"
Bob Thompson
Bob Thompson 2019 年 10 月 28 日
How do you differentiate between [24531] and [13542]?

サインインしてコメントする。

 採用された回答

Stephen23
Stephen23 2019 年 10 月 28 日
>> 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

その他の回答 (1 件)

Yuan Li
Yuan Li 2019 年 10 月 28 日
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]

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by