Code covered by the BSD License  

Highlights from
char2cell

Be the first to rate this file! 12 Downloads (last 30 days) File Size: 3.18 KB File ID: #24915

char2cell

by Mirko Hrovat

 

03 Aug 2009

Converts a character array (or cell string) array to a cell string array using delimiters and rows.

| Watch this File

File Information
Description

CHARacter to(2) CELL array conversion.

Syntax:
     cellmat = char2cell(s,delim,rowseparate,trim);
     cellmat = char2cell(s,delim,rowseparate);
     cellmat = char2cell(s,delim);
     cellmat = char2cell(s);

If "s" is a character array, then it may be separted into a 1D cell array of strings based upon delimiters (which may be a single element or multiple elements (e.g. CRLF). If "s" is multidimensional then the rows or columns of "s" may be further divided into cell s. If "s" is a cell string array, then the cells may be further divided by specifying delimiters. Consecutive delimters are treated as one.

Delimiters can be specified as a single element or multiple elements. Non-printable or non-visible characters are supported through the typical Matlab designations as:
          \b - backspace
          \f - formfeed
          \n - linefeed
          \r - carriage return
          \t - tab
          \\ - backslash
          (a single \ suffices if it is a single or last element)
           Use ' ' to specify a white space character.

Default delimiter is white space if "rowseparate" is empty and is empty if "rowseparate" is either "true" or "false".

"rowseparate" - "true" designates that each row should be separated or "false" if each column should be separated. Only relevant if "s" is multidimensional.

"trim" - if "true" (default), leading and trailing spaces are deleted

% Examples:
% char2cell(['red? green33 blue++ '],['?3+']))
% ans = 'red'; 'green'; 'blue'; ''
% c=sprintf(['this is a test\nthis\tis the second line'])
% char2cell(c,{'\n','\t'})
% ans = 'this is a test'
% 'this'
% 'is the second line'

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
str2cell: a pedestrian cell creator

MATLAB release MATLAB 7.5 (R2007b)
Other requirements None
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
cell Mirko Hrovat 04 Aug 2009 10:07:30
char Mirko Hrovat 04 Aug 2009 10:07:30
string Mirko Hrovat 04 Aug 2009 10:07:30
parse Mirko Hrovat 04 Aug 2009 10:07:30
delimiter Mirko Hrovat 04 Aug 2009 10:07:30
tokenize Mirko Hrovat 04 Aug 2009 10:07:30

Contact us at files@mathworks.com