function [Astack,Arow]=srdStack(A)
%==========================================================================
% Stack matrix contents of each cell array component into a matrix.  
% If the matrices in each component do not have the same number of 
% columns, pad with columns of NaNs.
%==========================================================================
%
% For the matrix in cell array component, get dimensions
%
n=length(A);
mx=zeros(n,1);
nx=zeros(n,1);
for i=1:n
    [mx(i),nx(i)]=size( A{i} ); 
end    
maxn=max(nx);
maxm=max(mx);

%
% Initialize the "stacked" data matrix
%  
Astack=nan*zeros(sum(mx),maxn);
rowEnds=cumsum(mx);        
rowEnds=[0; rowEnds(:)];

%
% Stack matrices 
% 
for i=1:n 
    rows=rowEnds(i)+1:rowEnds(i+1);
    Astack(rows,1:nx(i))=A{i};
end
Arow=mx;
%==========================================================================
end