フィルターのクリア

How to sort vector alternatively

1 回表示 (過去 30 日間)
Vishal Sharma
Vishal Sharma 2017 年 1 月 21 日
編集済み: Stephen23 2017 年 1 月 21 日
I have a vector a=[1 3;3 4;3 6;4 8]; I want to alternatively sort matrix ‘a’ row wise (second column), i.e Highest element in second column should be row 1; second to highest element in second column shall be last row; third to highest element in second column shall be second row; and so on So, output shall be [4 8;3 4;1 3;3 6] Thanks
This command is working for sorting in order only b=sortrows(a,-2);

採用された回答

Stephen23
Stephen23 2017 年 1 月 21 日
編集済み: Stephen23 2017 年 1 月 21 日
>> a = [1,3; 3,4; 3,6; 4,8]
a =
1 3
3 4
3 6
4 8
>> tmp = sortrows(a,2);
>> [tmp(1:2:end,:);flipud(tmp(2:2:end,:))]
ans =
1 3
3 6
4 8
3 4
@Vishal Sharma: did you know that the less effort you put into solving your own homework problems then the less you will learn. Also note that copying someone else's works and presenting it as your own is called plagiarism, and in many countries is considered a serious criminal offense.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by