Code covered by the BSD License  

Highlights from
mergecellkey: Merge cell by key

image thumbnail

mergecellkey: Merge cell by key

by

 

mergecellkey: Merge cell by key

mergecellskey(varargin)
function cellB = mergecellskey(varargin)
% PURPOSE: merge cells 
% -----------------------------------------------------------------------------
% SYNTAX: 
%         (1) C = mergecellskey(A,B,{'key1','key2'});
%         (2) C = mergecellskey(A1,A2,A3, {'key1'});
% -----------------------------------------------------------------------------
% OUTPUT: 
%       (1) A new cell contain all columns of the cells  
% -----------------------------------------------------------------------
% INPUT: 
%       (1) cells: NxM --->several cell containing M columns. Each cell
%       should contains a colomn with 'key' on the headline
%       (2) keys: 1xM ---> a cell containing the keys, it should string cell.
%       NB: no string can be include in the file.

% -----------------------------------------------------------------------
% LIBRARY: showcell
% -----------------------------------------------------------------------
% SEE ALSO: join  
% -----------------------------------------------------------------------
% REFERENCE: join, eval
% -----------------------------------------------------------------------
% written by:
%  Lin Renwen
%  <linrenwen@gmail.com>

% Version 1.0 [2012-11-9 11:55:15]

%=============================================
% EXAMPLE:
% A = {'Year', 1979, 1980 1981 1982 ; 'a' ,1,5,2, 4; 'c', '4', '3', '4','9yy'}';
% B = {'Year', 1980 1981 1982 1983; 'a' ,NaN,2,4,7 ; 'c', '3', '4', '677','pp'}';
% C = mergecellskey(A,B,{'Year'});
% showcell(C);
% %  END OF EXAMPLE
%=============================================
if nargin < 2
    error('Input of cells should more than 2');
end
if ~iscellstr(varargin{end})
    error('Keys for merge is not find!');
end


if nargin >2
    cellB = varargin{1};    
    for ii=2:(nargin-1)
        cellB = mergecellkey(cellB, varargin{ii}, varargin{end});
    end
elseif nargin == 2 && iscell(varargin{1})
    cellB = varargin{1}{1};    
    for ii=2:length( varargin{1})
        cellB = mergecellkey(cellB, varargin{1}{ii}, varargin{end});
    end
else
    warning('noteice');
end

end

Contact us