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

8 次查看(过去 30 天)
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');

回答(2 个)

Salaheddin Hosseinzadeh
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 2015-6-7
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');

类别

Help CenterFile Exchange 中查找有关 Text Data Preparation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by