I want to animate this function through time

3 visualizaciones (últimos 30 días)
L
L el 15 de Ag. de 2018
Editada: Walter Roberson el 15 de Ag. de 2018
I have a function T producing temperatures through time and depth and can plot individual temperature profiles in time (see attached image), but want to animate it so it is a single line moving through time. I have tried the "animatedline" function without success so far. I want to show the line moving through time as a function of temperature and depth. Is animatedline the proper command or should I use something else?
%settings
conductivity=.0033; %W m-1 K-1
heat_capacity=671.8; %J kg-1K-1
density=1300; %kgm-1^3
diffusivity=conductivity/(heat_capacity*density);
synodic_period=2.55e6; %seconds
synodic_frequency=(2*pi)/synodic_period;
T_av=250; %K
T_amp=150; %K
skin_depth=sqrt(2*diffusivity/synodic_frequency);
t_list=linspace(0,synodic_period,20); %time
%t_list = 0:5:synodic_period;
z_list=linspace(0,.5,100); %depth
T=nan(length(t_list),length(z_list)); %output vector
for t_index=1:length(t_list)
t=t_list(t_index); %first timestep
for z_index=1:length(z_list)
z=z_list(z_index);
T(t_index,z_index)=T_av+T_amp*exp(-z*sqrt(synodic_frequency/(2*diffusivity)))*cos(synodic_frequency*t-z*sqrt(synodic_frequency/(2*diffusivity)));
end
end
max_T=[];
for i=1:size(T,2)
max_T(i)=max(T(:,i));
end
min_T=[];
for i=1:size(T,2)
min_T(i)=min(T(:,i));
end
%%graph
plot((T), (z_list));
hold on
plot((max_T), (z_list), 'k-', 'LineWidth', 1.0)
set (gca,'YDir','reverse');
plot((min_T), (z_list), 'k-', 'LineWidth', 1.0);
title('Temperature Profile')
xlabel('Temperature (K)')
ylabel('Depth (m)')

Respuestas (1)

jonas
jonas el 15 de Ag. de 2018
Editada: Walter Roberson el 15 de Ag. de 2018
read here
I would rather update the xdata and ydata of your line handle in a for loop, perhaps with a pause() at the end to reduce the speed.
  2 comentarios
L
L el 15 de Ag. de 2018
Hi Jonas, thank you, I am working on this (new to Matlab).
jonas
jonas el 15 de Ag. de 2018
Editada: jonas el 15 de Ag. de 2018
No problem! Just let me know if you need help. It is always easier if you provide some sample data to work with!
If I understand correctly, each row in T describe a temperature profile that you want to plot against z_list (depth). Basically you write something like this
figure;hold on
h=plot(T(1,:),z_list)
for i=2:size(T,1)
h.XData=T(i,:)
pause(0.1)
end

Iniciar sesión para comentar.

Categorías

Más información sobre Animation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by