MATLAB Answers

How to write a 'text' at the end of another one

4 views (last 30 days)
Alessandro Esposito
Alessandro Esposito on 7 Jun 2015
Answered: Jan on 7 Jun 2015
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');

Answers (2)

Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh on 7 Jun 2015
Hi Alessandro,
You have to use text, see matlab help for text please
text(Xposition,Yposition,'Your String!');
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
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');

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!