フィルターのクリア

How to adjust colors of animated plot3 over time

3 ビュー (過去 30 日間)
Hans van der Horn
Hans van der Horn 2020 年 2 月 17 日
コメント済み: darova 2020 年 2 月 20 日
Hi,
I would like to change colors over time in an animated plot.
The way I do it right now is to run a loop over the datapoints and taking a color from a char array called colors.
tstep = .1
figure(1)
for n = 1:length(x)
plot3(x(1:n),y(1:n),z(1:n), 'LineWidth', 1, 'Color', colors(n))
pause(.05)
Image = getframe(gcf);
im = frame2im(Image);
end
However, this will change the color of the entire line in case of a change in color, while I would like the previous points to say the color they were.
How could I fix this?
Thanks so much,
Best
Hans

回答 (1 件)

darova
darova 2020 年 2 月 17 日
Try this
n = 100;
colors = jet(100);
x = linspace(0,10,n);
y = sin(x);
cla
xlim([min(x) max(x)])
ylim([min(y) max(y)])
hold on
for i = 1:n-1
plot(x(i:i+1),y(i:i+1),'color',colors(i,:))
pause(0.1)
end
hold off
  2 件のコメント
Hans van der Horn
Hans van der Horn 2020 年 2 月 20 日
Thanks so much! I works for a 2D plot, but I don't think it works for a 3D (x, y, z) plot using plot3.
darova
darova 2020 年 2 月 20 日
It works for 3D also. Did you try?

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by