How do i change color in a 3d animated plot over time?
11 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!