MATLAB: Text position based on another Text

figureMATLABposition;text;units

I need to plot a vertical text (text 2) next to a horizontal text (text 1), if I use the the same position that I used to plot text1 they become superimposed.
I've tried to infer the second position based on the Extent property of text1, but I can't get the units right:
rec = txt.Extent;
pos_x = rec(1) + rec(3);
pos_y = rec(2);
text(pos_x,pos_y,txt2,'HorizontalAlignment','center','FontSize',sz,'Rotation',90,'Units','normalized');
I've tried also with units in pixels but that didn't worked either.
The figure is a time series, I couldn't find any convertion function.
From the documentation it seems to me that the Extent values are normalized but I dont know if anything else is needed to display the second position on those coordinates.
Any pointers?? (hehe…get it?)

Best Answer

I am not certain what the problem is.
Try something like this:
x = 1:20;
y = 10*sin(pi*x/5);
figure
plot(x, y)
grid
vtext = compose('%s\n%s\n%s\n','Vertical','text','example');
htext = compose('%s', 'Horizontal text example');
text(6,5,vtext,'VerticalAlignment','middle', 'HorizontalAlignment','right')
text(6,5,htext, 'HorizontalAlignment','left')
.