How do i change color in a 3d animated plot over time?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
DGM
le 13 Jan 2022
Modifié(e) : DGM
le 13 Jan 2022
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Animation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!