function [rankingStruc]=nic_rsdd_getCompRanking(appConfig)
% ranking the components using scores
% Input: appConfig - structure containing all parameters necessary for
% group
%-----------------------------------------------------------
%   Copyright (C) 2009 Neuroimage Computing Group, State Key Laboratory of
%   Cognitive Neuroscience and Learning, Beijing normal university
%	Written by Gwen Chen
%	Version=1.0;
%	Release=20090921;
%  Last Revised by Guiwen Chen
%-----------------------------------------------------------
%

%close all;
numSub =  length(appConfig.AppSubjectLabels);
numOfIC = appConfig.compNum;% the number of IC
outPrefix=appConfig.outPrefix;

indRankings=[];
indRankingsIndex=[];

outDir=appConfig.outDir;

% plot curve of agg and individual component
for i=1:numSub
    rankings=[];
    icaOut=fullfile(outDir,'mat',sprintf('%s_ica_br%d.mat',outPrefix,i));% load ICA of individual component
    dd=load(icaOut,'coefRanking');
    aggCoefRanking=1-dd.coefRanking;
    rankings=aggCoefRanking;

    % record coef of every individual component
    indRankings=[indRankings;rankings];

    [ar,ind]=sort(rankings,'descend');
    [ar,ind]=sort(ind);
    % the index of component 
    indRankingsIndex=[indRankingsIndex;ind]; 
end



means=mean(indRankings,1);

stds=std(indRankings);

if(size(indRankings,1)>1)
    rankingBy=means./stds; % mean coef of individual component / standard deviation of componnet
else
    rankingBy=means;
end

[a b]=sort(rankingBy,'descend');

rankingIndex=b;
rankingResult=a;

rankingStruc.rankingScores=rankingResult;
rankingStruc.rankingIndex=rankingIndex;
