ranking a cell array

4 ビュー (過去 30 日間)
Richard
Richard 2012 年 3 月 1 日
Take the following example:
clear all
Name1 = {'Data1','Data2','Data3','Data4'};
Data = {6.2,6,3.2,8};
CombnsName = nchoosek(Name1,2);
CombnsData = nchoosek(Data,2);
for i = 1:length(CombnsData);
multiplied{i} = CombnsData{i,1}.*CombnsData{i,2};
end
multiplied = multiplied';
Final = [CombnsName, multiplied];
Rankd = sort(cell2mat(multiplied));
Here, Final represents the values gained by multiplying every possible combination of 'Name1'. Now, I'm trying to find a way of changing the order of 'Final' to correspond to the ranking order defined by 'Rankd'. For example the first 'line' of Final should read 'Data2 'Data3' 19.2; and the last 'line' should read 'Data1' Data4' 49.6.
Is there a method for doing this?

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 3 月 1 日
Cresult = cellfun(@times,CombnsData(:,1),CombnsData(:,2))
[C,id] = sort(Cresult);
out = [CombnsName(id,:) num2cell(C)]
  2 件のコメント
Richard
Richard 2012 年 3 月 1 日
also just came across the command sortrows which works
Andrei Bobrov
Andrei Bobrov 2012 年 3 月 1 日
yes
out = sortrows([CombnsName cellfun(@times,CombnsData(:,1),CombnsData(:,2),'un',0)],3)

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by