A much improved CHAR2LINE
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 (2025). A much improved CHAR2LINE (https://www.mathworks.com/matlabcentral/fileexchange/15722-a-much-improved-char2line), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |