MATLAB: How to fix a text’s location on a plot, without giving text’s axises

matlab text

I would like to add a text on my plots. I am using the text(x,y,textword) function to do so. But I have a problem about fixing them at the corner of my plot. Because I have 20sets of data that I need to plot, each of them has slightly different x&y scales. Thus I cannot give a 'certain' x and y location to my textwords. If there a way I can tell MATLAB to display the text on the top right corner of each of plot, without per-define the text's location?
thanks.

Best Answer

You can get xlim and ylim, then set x and y accordingly.
xl = xlim();
yl = ylim();
xWidth = xl(2)-xl(1);
yHeight = yl(2)-yl(1);
% Set x 90% of the way over.
x = xl(1) + 0.90 * xWidth;
% Set y 5% of the way up from the bottom.
y = yl(1) + 0.05 * yHeight;
text(x, y, 'Here I am!');
Related Question