Animation: Color changing over time
18 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (2)
Chad Greene
le 2 Août 2017
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 commentaires
Chad Greene
le 2 Août 2017
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
le 19 Fév 2020
Modifié(e) : reem farrag
le 19 Fév 2020
how i can draw a square on matlab that changes its color according to analogue values from arduino?
0 commentaires
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!