Borrar filtros
Borrar filtros

How to replace the 'erasemode' with 'animatedline'?

12 visualizaciones (últimos 30 días)
子宸 白
子宸 白 el 24 de Nov. de 2022
Respondida: Aiswarya el 7 de Sept. de 2023
I'm trying to modle a six springs system and I've found a similar code with erasemode which can no loger be used. I've tried to mode the oscillations precess with new functions, but I've failed to make it to work. Could you please help me use new functions to show the motion of the rings in the large ring.
this is the sub function that show the place of the ring and springs:
function [xp,yp]=plotstring(xa,ya,xb,yb,r)
[xa1,ya1]=cart2pol(xa,ya);
xa1=xa1+0.1;
[xa,ya]=pol2cart(xa1,ya1);
[xb1,yb1]=cart2pol(xb,yb);
xb1=xb1+0.1;
[xb,yb]=pol2cart(xb1,yb1);
a=0.13;n=5;
q2=[];
d=sqrt((xa-xb)^2+(ya-yb)^2);
w=2*pi*n/d;
x=xa:0.02:(xa+d);
y=a*sin(w*(x-xa));
if xa>xb
q1=pi+atan((ya-yb)/(xa-xb));
else
q1=atan((ya-yb)/(xa-xb));
end
xd=xa+(x-xa)*cos(q1);
yd=ya+(x-xa)*sin(q1);
for i=1:length(y)
if xd(i)<0
q2a=pi+atan((yd(i))/xd(i));
q2=[q2 q2a];
else
q2a=atan((yd(i))/xd(i));
q2=[q2 q2a];
end
end
xp=(r+y).*cos(q2);
yp=(r+y).*sin(q2);
this is the main function:
function bh
m=1;k=50;
%计算本征值与本征频率
S=m/k*diag(ones(1,6));
P=2*diag(ones(1,6))-diag(ones(1,5),-1)-diag(ones(1,5),+1);
P(1,6)=-1;P(6,1)=-1;
[JM,JBB]=eig(S\P);
JB=abs(sqrt(JBB));
%给定位移表达式中各项的系数
a1=[0.2,0,0,0,0,0,1];
a2=[0,0.2,0,0,0,0,1];
a3=[0,0,0.2,0,0,0,1];
a4=[0,0,0,0.2,0,0,1];
a5=[0,0,0,0,0.2,0,1];
a6=[0,0,0,0,0,0.2,1];
%设初相
phi1=0;phi2=0;phi3=0;
phi4=0;phi5=0;phi6=0;
t=0:0.01:4;%设运动时间
r=1;%圆环半径
figure
axis([-1.5*r 1.5*r -1.5*r 1.5*r]);
hold on
the1=0:2*pi/3600:2*pi;
plot (r*cos(the1),r*sin(the1),'r')
axis equal
for kk=1:7
if kk==7 %加文字标注
title('一般模式')
else ti1='简正模\cdot\cdot\cdot';ti2=int2str(kk);
ti=[ti1,ti2];
title(ti);
end
for i=1:6
ss=a1(kk)*JM(i,1)*cos(JB(1,1)*t+phi1)+a2(kk)*JM(i,2)*cos(JB(2,2))+a3(kk)*JM(i,3)*cos(JB(3,3))+a4(kk)*JM(i,4)*cos(JB(4,4))+a5(kk)*JM(i,5)*cos(JB(5,5))+a6(kk)*JM(i,6)*cos(JB(6,6));
x{i}=r*cos((i)*pi/3-ss/r);
y{i}=r*sin((i)*pi/3-ss/r);
end
for i=1:5
[xp,yp]=plotstring(x{i}(1),y{i}(1),x{i+1}(1),y{i+1}(1),r);
h{i}=plot(xp,yp,'erasemode','xor','linewidth',1.5);%画弹簧
hh{i}=plot(x{i}(1),y{i}(1),'erasemode','xor','marker','o','markersize',25,'linewidth',2.5,'color','r');
ii=7-i;
hhh{i}=text(x{6}(1)-0.08,y{i}(1)+0.01,int2str(ii),'fontsize',14,'erasemode','xor');
end

Respuesta aceptada

Aiswarya
Aiswarya el 7 de Sept. de 2023
Hi,
I understand that you are trying to use a code which uses erasemode but since it has been removed from all graphics objects, you would like to know how to use the new functions for the same.
To achieve similar effects as obtained by setting EraseMode to xor, you can use drawnow update or drawnow expose:
  • drawnow update updates a graph with maximum loop speed, but only sends updates if the renderer is free. If the renderer is busy, then drawnow update discards the updates.
  • drawnow expose updates a graph as quickly as possible without losing any updates.
For more information you can refer to the documentation of drawnow: https://www.mathworks.com/help/matlab/ref/drawnow.html
You can replace the EraseMode in your code with drawnow, animatedline and addpoints.
h = animatedline('LineWidth',1.5);
g = animatedline('marker','o','markersize',25,'linewidth',2.5,'color','r');
And in the for loop:
for i=1:5
[xp,yp]=plotstring(x{i}(1),y{i}(1),x{i+1}(1),y{i+1}(1),r);
addpoints(h,xp,yp);
drawnow expose;
addpoints(g,x{i}(1),y{i}(1));
drawnow expose;
To produce overlaid colors, use transparency (FaceAlpha option) instead of setting Erasemode to xor.

Más respuestas (0)

Categorías

Más información sobre Animation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by