0001 function s = wrapstring(s, n)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 if ischar(s)
0014 s = [cellstr(s)];
0015 end
0016
0017
0018 x = splitstring(s{end}, n);
0019 if strcmp(char(x), char(s))
0020 return
0021 end
0022
0023
0024 while length(s{end}) >= n
0025 if length(s) > 1
0026 s1 = s(1:end-1);
0027 else
0028 s1 = [];
0029 end
0030 s2 = splitstring(s{end},n);
0031 if isempty(s2)
0032 break
0033 end
0034 s = [s1 s2];
0035 end
0036
0037
0038
0039 function s = splitstring(s,n)
0040
0041
0042
0043 fi = 0;
0044 idx = find(s==' ' | s == ',' | s == '(' | s == '=');
0045 if max(idx) > n
0046 for i=1:length(idx)
0047 if idx(i) > n & fi==0
0048 fi = i;
0049 end
0050 end
0051 j = idx(fi);
0052 s = [cellstr(strtrim(s(1:j))) cellstr(strtrim(s(j+1:end)))];
0053 else
0054 s = [];
0055 return;
0056 end