How to write a 'text' at the end of another one
5 views (last 30 days)
Hi everybody and thanks in advance for taking a look at my question.
My problem is simple: I want a 'text' in a MATLAB 'figure' to be show at a location "relative to a second text". I need to plot 2 things and I'd like to have the second 'text' to be shown at the end of the first one. Forgive me for my bad English hope I was able to explain the problem. Thanks, Alessandro. PS:**whatdoiputhere** should be the length of 'Moto del CIR' translated in whatever unit MATLAB uses in figures and "normalized" so that I have one text just after the other one. Here is my actual problem:
text(0,1.0,['Moto del CIR.'],'color',[0 0 1],'units','normalized','VerticalAlignment','bottom');
plot(xg(i),yg(i),'.r') ; plot(xg(1:i),yg(1:i),'r') ;
text(**whatdoiputhere?**,1.0,['Moto del Baricentro.'],'color',[1 0 0],'units','normalized','VerticalAlignment','bottom');
Salaheddin Hosseinzadeh on 7 Jun 2015
You have to use text, see matlab help for text please
To plot relative to the first position just add a value to x and y positions
dX = 2;
dY = 4; % for example
text(Xposition+dX, Yposition+dY,'your new string')
Something like this should solve your problem
Jan on 7 Jun 2015
You can obtain the extent of the first text tolocate the correct position of the second text:
TextH = text(0, 1.0, 'Moto del CIR.', ...
'color', [0, 0, 1], ...
'units', 'normalized', 'VerticalAlignment', 'bottom');
Ext = get(TextH, 'Extent');
text(Ext(3), 1.0, 'Moto del Baricentro.', ...
'color', [1, 0, 0], ...
'units', 'normalized', 'VerticalAlignment','bottom');