% Combine all cells into one array
% combined = cellcombine(cellarray,stack)
%
% if stack=1 (default=0), then stack cells on top
% otherwise, they will be concatenated

function combined = cellcombine(cellarray,stack)
    
    if nargin<2 || isempty(stack)
        stack = 0;
    end

if length(size(cellarray))>2 || min(size(cellarray))>1
   error('This only works for cell arrays up to 1D');
end
combined = [];

for i=1:length(cellarray)
      if (size(cellarray{i},1)==1 && ~stack) || (size(cellarray{i},2)==1 && stack)
           combined = [combined cellarray{i}];
      else	
           combined = [combined;cellarray{i}];
      end
end
