how to find the actual length or coordinates of the xlabel in matlab

label, matlab, plot, text

Solution

Text objects have an "Extent" property:

Extent

Position and size of text. A four-element vector that defines the size and position of the text string:

[left,bottom,width,height]

If the Units property is data (the default), left and bottom are the x- and y-coordinates of the lower left corner of the text Extent.

For all other values of Units, left and bottom are the distance from the lower left corner of the axes Position rectangle to the lower left corner of the text Extent. width and height are the dimensions of the Extent rectangle. All measurements are in units specified by the Units property.

Problem

I am using the following code to find the position of the xlabel in a figure of matlab. ``` xlabel('X'); get(get(gca,'XLabel'),'Position'); ``` which gives me some coordinates (0.4981 -0.0669 1.0001). I think that coordinate is just the position of the top-left point of the label. So how do I found the bound for the label if I know the fontsize only?

Original source