Home > utils > cell2str.m

cell2str

PURPOSE ^

[s] = cell2str(cs,delim);

SYNOPSIS ^

function [s] = cell2str(cs,delim)

DESCRIPTION ^

 [s] = cell2str(cs,delim);

 Takes a cell array filled with strings and returns a concatenation in a
 single string. If delimiter is specified, it separates the individual strings
 with the delimiter.

 This function is useful in conjunction with sprintf statements

 Copyright (c) 2003-2012 The Regents of the University of California
 All Rights Reserved.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [s] = cell2str(cs,delim)
0002 % [s] = cell2str(cs,delim);
0003 %
0004 % Takes a cell array filled with strings and returns a concatenation in a
0005 % single string. If delimiter is specified, it separates the individual strings
0006 % with the delimiter.
0007 %
0008 % This function is useful in conjunction with sprintf statements
0009 %
0010 % Copyright (c) 2003-2012 The Regents of the University of California
0011 % All Rights Reserved.
0012 
0013 % 4/23/03 Petr Janata
0014 % 10/23/10 PJ - added handling of empty cell array
0015 
0016 if nargin < 2
0017   delim = '';
0018 end
0019 
0020 s = '';
0021 nelem = length(cs);
0022 
0023 if nelem == 0
0024   return
0025 end
0026 
0027 for ic = 1:(nelem-1)
0028   s = eval(['sprintf(''%s%s' delim ''',s,cs{ic})']);
0029 end
0030 
0031 s = sprintf('%s%s', s, cs{end});
0032 
0033 return

Generated on Thu 23-May-2019 04:00:50 by m2html © 2003