function [] = plotcomponents(inRes,inLambda)
%function [] = plotcomponents(inRes,inLambda)
%
% Plot all components in the same figure for a specific value of lambda.
%
% Input:
%   inRes: output from POCREPath();
%   inLambda: prespecifed lambda.
%
% Dabao Zhang    June 18, 2014
%
% Revised by:
%
% Copyright (c) 2014 by Dabao Zhang.

error(nargchk(1, 2, nargin));
if( nargin<2 ) 
    idxC= 1;
else
    lambdaList = [inRes(1:end).lambda];
    [minDiff,idxC] = min(abs(lambdaList-inLambda));
end

[p,ny] = size(inRes(idxC).beta);
tmpstr = '';
for k=1:ny
    if( ny>1 )
        tmpstr = ['Y_' num2str(k) ': '];
    end
    
    figure;
    for j=1:inRes(idxC).nCmp
        subplot(inRes(idxC).nCmp,1,j);
        h = plot(1:p,inRes(idxC).varpi(:,j),'x');
        ylabel(['\varpi_' num2str(j)]);
        xlabel('index of predictor');
        if( isfield(inRes(idxC),'pvalue') )
            title([tmpstr 'p-value of X\varpi_' num2str(j) '=' ...
                   num2str(inRes(idxC).pvalue(j))]);
        else
            title(tmpstr);
        end
    end
end
