Animation: Color changing over time
조회 수: 17 (최근 30일)
이전 댓글 표시
I have points on a 2D graph. Each data point has a file of data that is a change in temperature over time. I know how to assign the colors to each point, but I want to be able to do this in a movie that shows the colors of the points changing over time. I think I need to use a for loop but that hasn't worked so far.
Thanks!
댓글 수: 0
답변 (2개)
Chad Greene
2017년 8월 2일
Hi Sarah,
Indeed, a loop is the way to do it. Change the cdata each time through the loop. Be sure to set the color axis (caxis) limits to the total range of interest so the meaning of each color will stay consistent through each frame of the animation. Try running this example:
% for 20 time steps:
t = 1:20;
% starting locations of 30 points:
x = 100*rand(30,1);
y = 100*rand(30,1);
% starting temperatures:
T = 20+500*rand(30,1);
% Make the first frame:
figure
h = scatter(x+50*sind(t(1)/5),y+50*sind(t(1)/3),60,T*sind(t(1)/2),'filled');
% set x/y axis limits:
axis([0 100 0 100])
% set color axis limits:
caxis([20 25])
cb = colorbar;
ylabel(cb,'temperature')
% write the first frame:
% gif('temperaturedata.gif') <-uncomment to make a gif
% Loop through each subsequent time step:
for k = 2:length(t)
set(h,'xdata',x+50*sind(t(k)/5),'ydata',y+50*sind(t(k)/3),...
'cdata',T*sind(t(k)/2))
pause(0.1) % <-not necessary for making a gif
% gif <-uncomment to make a gif
end
댓글 수: 3
Chad Greene
2017년 8월 2일
Yes, of course! Just set the data to whatever values correspond to each time step, each time through the loop. Any values that do not change don't need to be updated each time through the loop. Just set 'cdata' each time through the loop if only the color data (temperature) is changing. Set the 'xdata' and 'ydata' if those values also change at each time step.
reem farrag
2020년 2월 19일
편집: reem farrag
2020년 2월 19일
how i can draw a square on matlab that changes its color according to analogue values from arduino?
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Animation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!