how can i classify my matrix

1 回表示 (過去 30 日間)
ali hadjer
ali hadjer 2015 年 11 月 15 日
回答済み: Stephen23 2015 年 11 月 16 日
heloo
i have a matrix with two vectors
i want to classify this matrix depending on the second vector for exemple
i have this matrix:
  1. 1 2 3 4 5
  2. 23 3 15 1 32 4
MY MATRIX AFTER CLASSIFICATION WILL BE
  1. 4 2 6 3 1 5
  2. 1 3 4 15 23 32
| MY CODE|
clc;
n=5;
x= 100;
y=100;
net = [rand([1,n])*x;rand([1,n])*y]
%v=SORTROws

採用された回答

Stephen23
Stephen23 2015 年 11 月 16 日
In just one line:
>> X = [1,2,3,4,5,6;23,3,15,1,32,4];
>> sortrows(X.',2).'
ans =
4 2 6 3 1 5
1 3 4 15 23 32

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 11 月 16 日
[~, idx] = sort(net(2,:));
sorted_net = net(:,idx);

カテゴリ

Help Center および File ExchangeClassification についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by