how can I sort the arrays according to example I explained below?

1 回表示 (過去 30 日間)
Rengin
Rengin 2016 年 6 月 15 日
回答済み: Elias Gule 2016 年 6 月 15 日
% Dear users, could you help me with sorthing the arrays I explain below:
% Let's say I have 3 equations:
% a+3b+5c+2d+4e=51
% 2a+5b+3c+d+6e=25
% 4a+2b+6c+3d+e=34
% CoEff=[1 3 5 2 4;2 5 3 1 6;4 2 6 3 1];
% Result= [51 25 34];
% According to the lowest value in "Result" matrix I want to sort CoEff and
% Result matrices. In the end I should have the matrices below:
% Sorted_CoEff=[2 5 3 1 6;4 2 6 3 1;1 3 5 2 4];
% Sorted_Result=[25 ; 34 ; 52];
% Thanks a lot for your help!

採用された回答

Adam
Adam 2016 年 6 月 15 日
編集済み: Adam 2016 年 6 月 15 日
[Result, idx] = sort( Result );
CoEff = CoEff( idx, : );

その他の回答 (2 件)

TastyPastry
TastyPastry 2016 年 6 月 15 日
[Result,ind] = sort(Result);
CoEff = CoEff(ind,:);
Result = Result';

Elias Gule
Elias Gule 2016 年 6 月 15 日
Ok, try this.
CoEff=[1 3 5 2 4;2 5 3 1 6;4 2 6 3 1];
Result= [51 25 34];
[~,locs]=ismember(sort(Result),Result); %%
CoEff = CoEff(locs,:);

カテゴリ

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