TimeIsNear
TimeIsNear

Reputation: 755

Matlab - change height of the text field on the whole figure

Is there a way to change the height of a text field on the whole figure without changing the x and y position?

To change we must use the position, which requires to change the coordinates. I would like to change only the height, without changing x and y.

Upvotes: 1

Views: 182

Answers (4)

StrongBad
StrongBad

Reputation: 879

One can set the Margin property of a text object to increase the height of the object without changing the fontsize, but this influences both the height and the width of the text object. I am not sure what it means to make the height smaller than what Matlab thinks is the text height, so I will assume you are interested in increasing the size.

Increasing the height of the text object is relatively easy if you are willing to use the LaTeX interpreter. You just need to add an "empty" box of whatever height you want:

text(0.5, 0.25, 'Hello World\parbox{\textwidth}{\vspace{1in}}', 'Interpreter', 'LaTeX', 'BackgroundColor',[1, 0, 0]);

This won't increase the height by exactly 1 inch, instead it will be more like 1 inch minus a baseline skip. Determining the actual height increase in displayed units adds even more problems. You might be able to change the height with unicode characters, and hence skip the LaTeX interpreter, but I have no idea how.

Upvotes: 1

Oleg
Oleg

Reputation: 10676

I am assuming you are working with uicontrol('style','text').

From the uicontrol properties you have:

Position

position rectangle

*Size and location of uicontrol*. The rectangle defined by this property 
specifies the size and location of the control within the parent figure 
window, uipanel, or uibuttongroup. Specify Position as:

[left bottom width height]

where left and bottom define the distance from the lower-left corner of the 
container to the lower-left corner of the rectangle. width and height are the 
dimensions of the uicontrol rectangle.

You can then just change the width and height keeping the original left and bottom.

Upvotes: 1

MrAzzaman
MrAzzaman

Reputation: 4768

Just store the current x and y, and use those in your set call like so:

old_pos = get(text_field_handle,'Position');
set(text_field_handle,'Position',[old_pos(1:2),new_width,new_height]);

Upvotes: 2

am304
am304

Reputation: 13876

Well, you can change the FontSize property, this won't change the coordinates, but will increase width as well as height. See Text Properties in the doc for more details.

Upvotes: 1

Related Questions