フィルターのクリア

sort two matrix

4 ビュー (過去 30 日間)
george
george 2012 年 5 月 31 日
コメント済み: Steven Lord 2018 年 11 月 30 日
hi i have two matrix X,Y (same size) i want to sort X and the same time i want to take the matrix Y with the same changes as X
example:
X=[4,7,1,9] Y=[32,6,4,21]
after sort
X=[9,7,4,1] Y=[21,6,32,4]
thanks for your time!!!!

採用された回答

Thomas
Thomas 2012 年 5 月 31 日
[X,index]=sort(X,'descend')
Y=Y(index)
  3 件のコメント
Hugo Matias
Hugo Matias 2018 年 11 月 30 日
How do you do the same thing but without the descend part
i.e:
X=[4,7,1,9] Y=[32,6,4,21]
after:
X=[1,9,4,7] Y=[4,21,32,6]
Steven Lord
Steven Lord 2018 年 11 月 30 日
Neither your new X nor your new Y are sorted, so I assume you have a known vector of indices you used to reorder / "shuffle" one of those arrays. If so, use the same vector of indices to reorder the other array in the same way. In the example below, ind is the known vector of indices.
X = [4 7 1 9];
Y = [32, 6, 4, 21];
ind = [3 4 1 2];
X2 = X(ind)
Y2 = Y(ind)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by