フィルターのクリア

Animation: Color changing over time

22 ビュー (過去 30 日間)
Sarah Weatherly
Sarah Weatherly 2017 年 8 月 2 日
編集済み: reem farrag 2020 年 2 月 19 日
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!

回答 (2 件)

Chad Greene
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
After you get that running, uncomment the two lines if you want to use my gif function.
  3 件のコメント
Chad Greene
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.
Sarah Weatherly
Sarah Weatherly 2017 年 8 月 2 日
Alright, I think that will work. Thank you very much!

サインインしてコメントする。


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

カテゴリ

Help Center および File ExchangeAnimation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by