Effacer les filtres
Effacer les filtres

Animation: Color changing over time

22 vues (au cours des 30 derniers jours)
Sarah Weatherly
Sarah Weatherly le 2 Août 2017
Modifié(e) : reem farrag le 19 Fév 2020
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!

Réponses (2)

Chad Greene
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
After you get that running, uncomment the two lines if you want to use my gif function.
  3 commentaires
Chad Greene
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.
Sarah Weatherly
Sarah Weatherly le 2 Août 2017
Alright, I think that will work. Thank you very much!

Connectez-vous pour commenter.


reem farrag
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?

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!

Translated by