Hello,
I want to generate the values of x on each subplot and i was wondering if there is a way to get the text or numbers placed in 'best' location than specifying (x,y) coordinates for the text location.
x(1) on plot 1
x(2) on plot 2 etc inside a forloop
thank you
dan

 채택된 답변

Star Strider
Star Strider 2022년 7월 30일

0 개 추천

One approach is to use the legend position after using the 'Location','best' name-value pair, and then interpolating the relative values to the relevant ‘x’ and ‘y’ values (and adding a ‘fudge factor’ if necessary).
x = 1:10;
y = randn(2,size(x,2));
figure
plot(x, y)
Ax = gca;
hl = legend('Location','best');
pos = hl.Position;
txtx = interp1([0 1],xlim,pos(1)*1.1);
txty = interp1([0 1],ylim,pos(2)*1.1);
delete(hl)
text(txtx,txty,'Hi there!')
Experiment to get the desired results.
.

댓글 수: 4

danel james
danel james 2022년 7월 30일
Great! I have to accept this answer :)
I generated numbers on each plot(decimal numbers)
But I want to get 2 decimals after the decimal point. Like 3.12 than 3.12345 etc on each plot Thank you again
Star Strider
Star Strider 2022년 7월 30일
As always, my pleasure!
I am not certain what you are asking, hwoever the round function should do that. (The original version rounded only to the nearest integer, however since R2014b, also to a fixed number of decimal places. If you have the earlier version, it is straightforward to create a version of it to round to a fixed number of decimal places.)
.
danel james
danel james 2022년 7월 30일
Not really! i want to prnit time for each particular plot and on top of each plot should be the corresponding time. But its howing me time has 4 digits after decimal place.
round(t,3) is not working at all
Star Strider
Star Strider 2022년 7월 31일
This is new, and not entirely well-described.
With respect to the text object, perhaps:
text(txtx,txty, sprintf('Time %.2f', time))
assuming here that ‘time’ is a scalar double. If it’s something else, I need to know. See the documentation on sprintf for details.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Nikolas
Nikolas 2024년 6월 5일

0 개 추천

Another way that may be more intuituve is to find the max of the x any y values and multiply them by a percentage for the location. for example: text(max(xdata)*.10,max(ydata)*0.9,'Heat Exchanger effectiveness'); Which is the equivilant to northwest location

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

질문:

2022년 7월 30일

답변:

2024년 6월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by