フィルターのクリア

Arranging a matrix rows with respect to another matrix

3 ビュー (過去 30 日間)
myetceteramail myetceteramail
myetceteramail myetceteramail 2018 年 5 月 19 日
編集済み: Jan 2018 年 5 月 19 日
I have a matrix, for example, A=[1 2; 3 5], and I have a matrix B=[2 7; 1 3] What I need to do is arrange the rows of B like the rows of A, in terms of the sum of each row. Since the first row of A has sum 3, and the second row has sum 8, now I need to arrange the rows of B such that first row of has the smaller sum i.e 4 and the second row has the bigger sum 9. How can this be done, some help?
  2 件のコメント
dpb
dpb 2018 年 5 月 19 日
Are there always only two rows?
myetceteramail myetceteramail
myetceteramail myetceteramail 2018 年 5 月 19 日
No, actually there are 50 rows and 50 columns in each matrix. I just posted this 2*2 example to get an idea of how to do this?

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

回答 (1 件)

Jan
Jan 2018 年 5 月 19 日
編集済み: Jan 2018 年 5 月 19 日
Does this what you want?
[~, order] = sort(sum(A, 2));
B2 = B(order, :)

カテゴリ

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