A much improved CHAR2LINE

Version 1.0.0.0 (1.56 KB) by Ian Howat
Returns a character array or cellstr as a single, delimited string. Useful for building ascii files.
1.8K Downloads
Updated 30 Jul 2007

View License

CHAR2LINE Make a single spaced or delimited line from a char or cellstr.
B = char2line(A) puts each row of a character array or each cell in a cell array of strings into a single line separated by spaces. If A is a cellstr, the output string will be ordered by rows.
B = char2line(A,'delimiter') separates each string by 'delimiter'.

Example 1:
>> A = char('An','example','of','char2line');
>> char2line(A)
ans =
An example of char2line
Example 2:
>> char2line(A,',')
ans =
An,example,of,char2line
Example 3:
A = repmat(cellstr(A),[1,2])
A =
'An' 'An'
'example' 'example'
'of' 'of'
'char2line' 'char2line'
>> char2line(A)
ans =
An An example example of of char2line char2line

Thanks to jos x for suggestions in improving this function.

Cite As

Ian Howat (2024). A much improved CHAR2LINE (https://www.mathworks.com/matlabcentral/fileexchange/15722-a-much-improved-char2line), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2006a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Data Type Conversion in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0