You can accomplish this task using the 'textwrap' and 'fprintf' functions in a manner similar to the following example.
The 'textwrap' function will break a string into a cell array of string in order to fit within the specified UIControl object, or can be set to use a max line width. Then 'fprintf' can print this cell array of string to a '.txt' file using the syntax below:
'It appears wrapped within the UIControl '...
'object, and should be written to a file '...
'with that same appearance']}
txt = textwrap(h,txt)
fprintf(fid, '%s\n', txt{:});
fclose(fid);
Best Answer