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

조회 수: 17 (최근 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 CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by