这是对this question的后续,在其中我试图同时动画两个函数。所提供的解决方案实际上满足了需求,因此我接受了它作为最终答案。
然而,当我试图为我的更现实的案例实现类似的东西时,我遇到了额外的问题。以下守则的目的是:
Stresses。第一个索引用于增量变化的值,第二个索引对应于Depth矩阵中的每个值,第三个索引对应于每个animatedline对象。Depth的2D矩阵,其中包含两行。每一行对应于一个animatedline。据我所知,这使用了与previous问题类似的格式。包括pause语句会导致同时但“不稳定”的绘图。不包括pause语句结果平滑,但“非同时”的绘图。也就是说,它只画了第二行。
我希望动画是平滑的,同时绘制两个animatedline对象。我怎样才能做到这一点?
发布于 2017-06-27 08:31:05
对于同时绘图,您缺少了hold函数。
close all
%%PLOT AND ANIMATE
nlines = 2;
% optional: so that you can distinguish between the two lines
colors = {'r','b'};
for n = 1:nlines
h(n) = animatedline('color',colors{n});
end
axis([-2.1,2,-10,0]);
for i = 1:50
for j = 1:3
Stresses(i,j,1) = (i/100)+j/3;
Stresses(i,j,2) = -(i/100)-j/3;
end
end
Depth = [0, -5, -10; 0,-6,-9];
for i = 1:size(Stresses,1)
for n = 1:nlines
n;
currentStresses = Stresses(i,:,n);
h(n).clearpoints();
h(n).addpoints(currentStresses, Depth(n,:));
% wait for another line
hold on
end
% clear hold
hold off
drawnow
end希望这能帮上忙!
https://stackoverflow.com/questions/44774950
复制相似问题