| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
outstring = textwrap(h,instring)
outstring = textwrap(h,instring,columns)
[outstring,position] = textwrap(...)
outstring = textwrap(h,instring) returns a wrapped string cell array, outstring, that fits inside the uicontrol with handle h. instring is a cell array, with each cell containing a single line of text. outstring is the wrapped string matrix in cell array format. Each cell of the input string is considered a paragraph.
outstring = textwrap(h,instring,columns) returns an outstring with each line wrapped at columns characters. Spaces are included in the character count.
[outstring,position] = textwrap(...) returns the recommended position of the uicontrol in the units of the uicontrol. position considers the extent of the multiline text in the x and y directions.
textwrap maintains the original line breaks in the input cell array and adds new ones. It can calculate uicontrol positions with any type of Units, including normalized units.
When programming a GUI, do not call copyobj or textwrap (which calls copyobj) inside a CreateFcn. The act of copying the uicontrol object fires the CreateFcn repeatedly, which raises a series of error messages after exceeding the root object's RecursionLimit property.
Place two text-wrapped strings in text uicontrols. The left one has a Position calculated by textwrap in Units of pixels; the right one's Position is calculated manually in Units of characters:
hf = figure('Position',[560 528 350 250]);
% Make a text uicontrol to wrap in Units of Pixels
% Create it in Units of Pixels, 100 wide, 10 high
pos = [10 100 100 10];
ht = uicontrol('Style','Text','Position',pos);
string = {'This is a string for the left text uicontrol.',...
'to be wrapped in Units of Pixels,',...
'with a position determined by TEXTWRAP.'};
% Wrap string, also returning a new position for ht
[outstring,newpos] = textwrap(ht,string);
set(ht,'String',outstring,'Position',newpos)
% Make another text uicontrol to wrap to a column width of 15
colwidth = 15;
% Create it in Units of Pixels, 100 wide, 10 high
pos1 = [150 100 100 10];
ht1 = uicontrol('Style','Text','Position',pos1);
string1 = {'This is a string for the right text uicontrol.',...
'to be wrapped in Units of Characters,',...
'into lines 15 columns wide.'};
outstring1 = textwrap(ht1,string1,colwidth);
% Reset Units of ht1 to Characters to use the result
set(ht1,'Units','characters')
newpos1 = get(ht1,'Position');
% Set new Position in Characters to be specified colwidth
% with height the length of the outstring1 cell array + 1.
newpos1(3) = colwidth;
newpos1(4) = length(outstring1)+1;
set(ht1,'String',outstring1,'Position',newpos1)

![]() | textscan | tfqmr | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |