It is really an excellent code. However, when I try to create a large geometry, it is still time consuming. The function 'swap' excutes too many string copy in the 'while' loop and it cost much time when there are a mount of data points. I rewrote the function as follow and the it only needs 1/3 time.
function s = wrap(str,delim,n)
tmp = blanks(n);
strlength = length(str);
i = 1;
index=1;
while (strlength-index+1>n)
tmp = str(index:index+n-1);
d = strfind(tmp,delim);
d = d(end);
index = index + d;
s(i,:) = [tmp(1:d) blanks(n-d)];
i = i+1;
end
if (strlength-index+1>0)
s(i,:) = [str(index:strlength) blanks(n-(strlength-index+1))];
end