從帖子不完全清楚你想要實現什麼。這裏有一個基於猜測和各種選項。
您的前兩個「表」存儲股票和天數的符號(與排名無關)。你的第三和第四個分數是以stock x day
的方式排列的。我們假設股票處於垂直,橫向數日,股票代表[1:10]
。
N = 10; % num of stocks
M = 10; % num of days
T3 = rand(N,M); % table 3 stocks x days
T4 = rand(N,M); % table 4 stocks x days
按升序評分表和降序(讓每天上較低的分數,每列IE):
[Sl,L] = sort(T3, 'descend');
[Ss,S] = sort(T4, 'ascend');
保持三個最大和最小:
largest = L(1:3,:); % bucket of 3 largest per day
smallest = S(1:3,:); % bucket of 3 smallest per day
如果你需要兩者都是(0是nan):
% Inter-section of both buckets
indexI = zeros(3,M);
for i=1:M
z = largest(ismember(largest(:,i),smallest(:,i)));
if ~isempty(z)
indexI(1:length(z),i) = z;
end
end
如果您需要那些在任何一個(0囡):
% Union of both buckets
indexU = zeros(6,M);
for i=1:M
z = unique([largest(:,i),smallest(:,i)]);
indexU(1:length(z),i) = z;
end
如果你需要得分/股從集largest_of_3和smallest_of_4的排名:
scoreAll = [Sl(1:3,:); Ss(1:3,:)];
indexAll = [largest;smallest];
[~,indexSort] = sort(scoreAll,'descend');
for i=1:M
indexBest(:,i) = indexAll(indexSort(1:3,i),i);
end
UPDATE
爲了得到最終得分的加權排名,在排序scoreAllW
而不是之前,定義權重向量(1 x分數)並使用以下兩個選項之一3210:
w = [0.3 ;0.3; 0.3; 0.7; 0.7; 0.7];
scoreAllW = scoreAll.*repmat(w,1,10); % Option 1
scoreAllW = bsxfun(@times, scoreAll, w); % Option 2
表3和表4的目的是什麼?表3和表4的內容是什麼?他們是表1中每個股票的每日數據? – TJ1 2013-02-10 15:48:43
合作編輯是SO的一部分http://stackoverflow.com/faq#editing「如果您不滿意您的貢獻是由其他可信用戶協作編輯的想法,那麼這可能不適合您。」考慮自己編輯您的帖子,根據數據和輸入/輸出抽象您的問題,並提供一個示例。 – gevang 2013-02-10 21:51:33