-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtextwrap2.m
31 lines (29 loc) · 886 Bytes
/
textwrap2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function stringOut = textwrap2(stringIn, nOfColumns)
%TEXTWRAP2 Wrap text string.
% OUT = TEXTWRAP2(IN, COL) wraps the given text string IN to fit into COL
% columns. The results is a string with line breaks '\n' inserted.
%
% OUT = TEXTWRAP2(IN) uses a default number of 75 columns.
%
% Note: This function uses the Matlab-function TEXTWRAP which returns a
% cell array with each cell containing one line of text.
%
% Example:
% disp(textwrap2(myString, 75));
%
% Markus Buehren
% Last modified 21.04.2008
%
% See also TEXTWRAP.
stringOut = '';
if nargin < 2
nOfColumns = 75;
end
if ischar(stringIn)
stringIn = {stringIn}; % function textwrap requires a cell array as input
end
stringOutCell = textwrap(stringIn, nOfColumns);
for k=1:length(stringOutCell)
stringOut = [stringOut, stringOutCell{k}, sprintf('\n')]; %#ok
end
stringOut(end) = ''; % remove last line break