Home > atmlab > handy > vector2commalist.m

vector2commalist

PURPOSE ^

VECTOR2COMMALIST Converts a vector to a comma seperated string

SYNOPSIS ^

function s = vector2commalist(x,varargin)

DESCRIPTION ^

 VECTOR2COMMALIST   Converts a vector to a comma seperated string

    Creates a comma seperated string of vector elements. The vector
    elements are converted to strings by *num2str*.

    An example:
       s = vector2commalist(0.1:0.2:1.3);
    gives
       s = '0.1,0.3,0.5,0.7,0.9,1.1,1.3';

 FORMAT   s = vector2commalist( x [,fstring] )
        
 OUT   s         The string.
 IN    x         The vector.
 OPT   fstring   Output format. Possible choices as for sprintf.
                 Default is '%g'.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

vector2commalist.m

SOURCE CODE ^

0001 % VECTOR2COMMALIST   Converts a vector to a comma seperated string
0002 %
0003 %    Creates a comma seperated string of vector elements. The vector
0004 %    elements are converted to strings by *num2str*.
0005 %
0006 %    An example:
0007 %       s = vector2commalist(0.1:0.2:1.3);
0008 %    gives
0009 %       s = '0.1,0.3,0.5,0.7,0.9,1.1,1.3';
0010 %
0011 % FORMAT   s = vector2commalist( x [,fstring] )
0012 %
0013 % OUT   s         The string.
0014 % IN    x         The vector.
0015 % OPT   fstring   Output format. Possible choices as for sprintf.
0016 %                 Default is '%g'.
0017 
0018 % 2005-06-08   Created by Patrick Eriksson.
0019 
0020 
0021 function s = vector2commalist(x,varargin)
0022 %
0023 [fstring] = optargs( varargin, { '%1g' } );
0024 
0025 s = '';
0026 
0027 for i = 1 : length(x)
0028 
0029   if i == 1 
0030     s = sprintf( '%s', num2str(x(i),fstring) );
0031   else
0032     s = sprintf( '%s,%s', s, num2str(x(i),fstring) );
0033   end
0034 end
0035

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005