function [] = plotbetanzbeta(inRes)
%function [] = plotbetanzbeta(inRes)
%
% Provide the plot of lambda vs. (beta, #[beta~=0]) for the results from
% POCREPath(...).
%
% Input:
%   inRes: output from POCREPath();
%
% Dabao Zhang    June 18, 2014
%
% Revised by:
%
% Copyright (c) 2014 by Dabao Zhang.

error(nargchk(1, 1, nargin));

nlambda = length(inRes);
lambda = [inRes(1:end).lambda];
if( ~issorted(lambda) )
    [lambda, idxL] = sort(lambda);
    inRes = inRes(idxL);
end

[p,ny] = size(inRes(1).beta);

nzbeta = zeros(ny,1);
for k=1:ny
    beta = zeros(p,nlambda);
    for j=1:nlambda
        beta(:,j) = inRes(j).beta(:,k);
        nzbeta(j) = sum(abs(inRes(j).beta(:,k))>eps);
    end
    
    figure; hold on;
    for j=1:(size(beta,1)-1)
        plot(lambda,beta(j,:),':x');
    end
    [ha,hl1,hl2] = plotyy(lambda,beta(end,:),lambda,nzbeta);
    set(hl1,'Marker','x');
    set(hl1,'LineStyle',':');
    set(hl2,'Marker','*');
    set(hl2,'LineStyle','-');
    set(get(ha(1),'Ylabel'),'String','\beta');
    set(get(ha(2),'Ylabel'),'String','number of non-zero  \beta');
    xlabel('\lambda');
    title(['Component of Y: ' num2str(k)]);
    hold off;
end
