How do i change color in a 3d animated plot over time?

11 ビュー (過去 30 日間)
Hamza Yusuf
Hamza Yusuf 2022 年 1 月 12 日
編集済み: DGM 2022 年 1 月 13 日
I have this code that animates a 3d plot with the frequency of 100 hz. I want to change the color of it but the current method I have now changes the color of the plot of the whole time and not just at that specific instance.
Here is the code:
t = 0:0.1:60;
x = 20*t; y = cos(t); z = sin(t);
view(3);
color=jet(size(t,2));
close all
for i=1:size(t,2)
plot3(x(1:1:i),y(1:1:i),z(1:1:i),'color',color(i,:))
axis([0 1800.7 -1.7 1.7 -1.3 1.3])
grid on
pause(0.01)
And above is the finished plot. I wanted to change the color so the whole spectrum could have been seen and not just the color red. And it has to change while being animated in the plot.

採用された回答

DGM
DGM 2022 年 1 月 13 日
編集済み: DGM 2022 年 1 月 13 日
Use hold and only draw one segment at a time. Note that for N points, there are N-1 segments, hence the length of the color table.
t = 0:0.1:60;
x = 20*t; y = cos(t); z = sin(t);
view(3);
hold on; grid on;
color = jet(size(t,2)-1);
for k = 2:size(t,2)
plot3(x(k-1:k),y(k-1:k),z(k-1:k),'color',color(k-1,:))
axis([0 1800.7 -1.7 1.7 -1.3 1.3])
pause(0.01)
end

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by