pause(t). Ahora supongamos que queremos mostrar esta variación del gráfico en un informe, vale decir, mostrarlo sobre papel. En ese caso lo mejor será mostrar unas instantáneas del gráfico en diferentes momentos.Obviamente nuestro gráfico cambiará a medida que avanza las iteraciones en nuestro programa, estas iteraciones pueden estar dadas por un bloque
for, while, etc.Para tomar las instantáneas utilizaremos el siguiente esquema
% tu código... % Todas las instantaneas que quieras snapshots = [i1 i2 i3 i4]; [sy,sx] = size(snapshots); % Inicia tu bloque iterativo for i = imin:istep:imax % tu código... if(sum(any(i==snapshots))) [m,n] = find(snapshots == i); figure(100) subplot(sy,sx,(m-1)*sx+n); plot( , , ); % copia y pega el mismo plot de tu código % Si quieres, agrega propiedades a los subplots % aquí end end
¡Pongámoslo en acción! Supongamos que queremos simular el movimiento parabólico de caída libre con el siguiente código (verás una animación si lo ejecutas):
vx = 20; vy0 = 100; x = 0; y = 0; for t = 0:.1:20 x = [x vx*t]; yt = vy0*t-5*t*t; y = [y yt]; figure(1) plot(x,y,'*b'); axis([0 500 0 600]); end
Si ahora queremos tomar las instantáneas agregaremos el esquema a nuestro código (copiar y pegar), escogeremos en qué momentos queremos tomar las instantáneas y lo volvemos a ejecutar.
vx = 20;
vy0 = 100;
x = 0;
y = 0;
snapshots = [ 5 10
15 20];
[sy,sx] = size(snapshots);
for t = 0:.1:20
x = [x vx*t];
yt = vy0*t-5*t*t;
y = [y yt];
figure(1)
plot(x,y,'*b');
axis([0 500 0 600]);
if(sum(any(t==snapshots)))
[m,n] = find(snapshots == t);
figure(100)
subplot(sy,sx,(m-1)*sx+n);
plot(x,y,'*b');
axis([0 500 0 600]);
title(strcat('Iteracion = ',int2str(t)));
end
end
Cuyo resultado es el siguiente
Si ahora solamente cambiamos snapshots a
snapshots = [ 5 10 12
15 17 20]Obtenemos

No hay comentarios:
Publicar un comentario