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

조회 수: 4 (최근 30일)
Alessandro Esposito
Alessandro Esposito 2015년 6월 7일
답변: Jan 2015년 6월 7일
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
Salaheddin Hosseinzadeh 2015년 6월 7일
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에서 String에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by