Problem with hold on plot

1 回表示 (過去 30 日間)
Cristián Vera
Cristián Vera 2020 年 2 月 3 日
コメント済み: Adam Danz 2020 年 2 月 4 日
Hi, im working with some data, specifically the particles in a nozzle.
The point is that I want to create an animation using plot and for. To do this, I made a sketch of the nozzle using simple lines with plot, then for takes care of showing particles.
The problem I have is that because I need to show the sketch and the particles, I use hold on, which generates a repetition in the data of particles, which I dont want. How can I solve this problem? Be able to graph the particles and the sketch in the animation without repeating particle data.
Here is the sketch:
bosquejo.jpg
And that's how it shouldn't look:
no.jpg
And this is how it should look, but with the background sketch:
si.JPG
Animation code, just in case:
figure
hold on
title(['Velocidad en alimentador ' titulo])
for time=1:20:size(Xt,2);
pointsize=5;
plot([180e-3,180e-3],[-10e-3,10e-3],'LineWidth',4)
plot([0,20]*1e-3,[17.5,17.5]*1e-3,'k',[20,40]*1e-3,[17.5,1]*1e-3,'k',[40,170]*1e-3,[1,8]*1e-3,'k',[170,170]*1e-3,[8,-8]*1e-3,'k',[170,40]*1e-3,[-8,-1]*1e-3,'k',[40,20]*1e-3,[-1,-17.5]*1e-3,'k',[20,0]*1e-3,[-17.5,-17.5]*1e-3,'k',[0,0]*1e-3,[-17.5,17.5]*1e-3,'k')
scatter(Xt(:,time),Yt(:,time), pointsize, Vt(:,time),'filled')
ylim([-18e-3,18e-3])
xlim([0e-3,180e-3])
pause(0.001)
end
I hope the question is understood.
Greeting and thank you very much in advance!

採用された回答

Adam Danz
Adam Danz 2020 年 2 月 3 日
The loop should only contain the data you're adding to the plot.
Try this out.
figure
axes()
hold on
ylim([-18e-3,18e-3])
xlim([0e-3,180e-3])
title(['Velocidad en alimentador ' titulo])
pointsize=5;
plot([180e-3,180e-3],[-10e-3,10e-3],'LineWidth',4)
plot([0,20]*1e-3,[17.5,17.5]*1e-3,'k',[20,40]*1e-3,[17.5,1]*1e-3,'k',[40,170]*1e-3,[1,8]*1e-3,'k',[170,170]*1e-3,[8,-8]*1e-3,'k',[170,40]*1e-3,[-8,-1]*1e-3,'k',[40,20]*1e-3,[-1,-17.5]*1e-3,'k',[20,0]*1e-3,[-17.5,-17.5]*1e-3,'k',[0,0]*1e-3,[-17.5,17.5]*1e-3,'k')
for time=1:20:size(Xt,2);
scatter(Xt(:,time),Yt(:,time), pointsize, Vt(:,time),'filled')
pause(0.001)
end
  9 件のコメント
Cristián Vera
Cristián Vera 2020 年 2 月 4 日
It worked!!! Thank you for your time and kindly help!
What a relief... =)
Adam Danz
Adam Danz 2020 年 2 月 4 日
Ha! Glad I could help.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnimation についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by