Is it possible to create a moving text along with a line??

 採用された回答

Jonas
Jonas 2021 年 7 月 6 日

1 投票

you can move the text every now and then by changing the coordinates. e.g.
data=randi(42,100,1);
m=mean(data);
plot(data);
yline(m);
tx=text(1,1.1*m,'some text','Color','r');
for xCor=2:80
tx.Position=tx.Position+[1 0 0];
pause(0.1)
end

5 件のコメント

Rajawarman Thiruselvam
Rajawarman Thiruselvam 2021 年 7 月 6 日
for example this is program below, how can i add moving text along with animated line
clear all
close all
clc
figure
h = animatedline('marker','o','color','b');
axis([1 10 1 7])
axis ij
grid on
x=1:4;
n = 100;
xx=linspace(x(1),x(end),n);
y = [1 1 2 1];
yy = interp1(x,y,xx);
for ci=1:n
addpoints(h,xx(ci),yy(ci));
pause(0.03);
drawnow
end
Jonas
Jonas 2021 年 7 月 6 日
similarily to this
h = animatedline;
axis([0,4*pi,-1,1])
x = linspace(0,4*pi,1000);
y = sin(x);
tx=text(x(1),1.1*y(1),'lead');
for k = 1:length(x)
addpoints(h,x(k),y(k));
tx.Position=[x(k),1.1*y(k)]
drawnow
end
Rajawarman Thiruselvam
Rajawarman Thiruselvam 2021 年 7 月 7 日
tx=text(x(1),1.1*y(1),'lead')
can you please explain this??
Rajawarman Thiruselvam
Rajawarman Thiruselvam 2021 年 7 月 7 日
and this ??
tx.Position=[x(k),1.1*y(k)]
Jonas
Jonas 2021 年 7 月 7 日
編集済み: Jonas 2021 年 7 月 7 日
tx=text(x(1),1.1*y(1),'lead');
creates the text label 'lead' near x(1) and y(1). i used 1.1*y(1) to be sure that the label is not exactly on the point of the curve i want to label but a bit above
similarly i use a slightly bigger y when i move the label according to the further points of the curve

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeAnimation についてさらに検索

製品

リリース

R2021a

質問済み:

2021 年 7 月 6 日

編集済み:

2021 年 7 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by