Take the 2-minute tour ×

my problem is I want to have a box for additional bigger comments to the graph. How can I create this box, so that it will be always on the right bottom side outside of my graph, and it will be automatically adjusting its size to the amount of text inside? Also, if I will have longer text, I need it to be split into more lines, not just one line extremely long.

I use it like that, however I have a poor control over what is happening, this just creates a certain size in a certain place, text is cut.. please help :)

x = rand(110)*100;
y = x;
MyBox = uicontrol('style','text')
set(MyBox,'String','optional longer information to be put into diagram')
share|improve this question

1 Answer 1

up vote 0 down vote accepted

I am afraid you can not do that automatically - Text boxes do not use callbacks. From the documentation:

Users cannot change static text interactively. Static text controls do not activate callback routines when clicked.

What you can do is call textwrap function, which will automatically wrap the text you pass to it and return new Text box position:

MyBox = uicontrol('style','text');
% set initial position - first three values are kept constant after wrap, the hight can be changed

% adjust the height of your Text box and wrap the text
[outstring,newpos] = textwrap(MyBox,{'optional longer information to be put into diagram'});
% set new position and text
set(MyBox,'Position',newpos, 'String', outstring)

You will have to call textwrap and set(...) yourself whenever you change the string in the text box.

share|improve this answer

Your Answer


