Here is an example of what I mean -
The above images are arranged in a Grid layout (using GUI Layout Toolbox), so each axes are in their own uicontainer, which means any text from one grid will be overlaid on top by the a subsequent grid, therefore hiding the text if it's beyond the boundary of its own grid. As you can see, the texts (.170) and (.txt) are partially hidden because of this.
To solve this problem, one would have to replace the extra text with ellipsis (...) to shorten the text and make it fit into the grid. An example is the Windows explorer, showing below, where the text (.170) is replaced with (.1...) as it is shorter in length.
Apparently, this requires the dertermination of the width (or length) of the actual text, which has a lot to do with the font size and font used. Unless it's monospaced font, using number of characters to determine the length is not enough. For example, 'iii' is much shorter than 'DDD' in width.
In MATLAB, although you can determine the width of the graphics text object, the extent of the box that encloses the text is a read-only property, therefore it's not possible to restrict the width of the text object (and MATLAB also has to know to put ellipsis when the text is restrained). A lengthy workaround would be to calculate the width of the text based on its font and font size, and if it's wider than the grid, you'll have to iteratively shortern its characters one by one and determine whether the shortened text would fit inside the grid, while adding ellipsis into the mix.