Matlab - Ayuda Animación de Simulación xyz

 
Vista:
Imágen de perfil de Serenyty

Ayuda Animación de Simulación xyz

Publicado por Serenyty (1 intervención) el 16/02/2015 20:25:03
Hola
Necesito ayuda , ya tengo el código para generar una Animación en X, Y, pero al querer generarla en XYZ me aparece un error.

Les dejor el código si alguien me puede ayudar. 100000 gracias

ANIMACION XY
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
x = 0;
 
y = 0;
 
xh = [x];
 
yh = [y];
 
n = 300
 
 
for paso = 1:n;   # Paso tiene el valor de 1, con el comando For hasta n
 
cambio = 0;
 
 
if (rand() > 0.7);   # Primera condicion para la variable "cambio"
 
cambio += 1;    # incremento para "cambio"
 
else
 
cambio -= 1;    # decremento para "cambio"
 
endif
 
 
if (rand() > 0.3);          # Segunda condicion para darle valores a "x" y "y"
 
x += cambio;    # incremento o decremento para "x"
 
 else
        y += cambio;    # incremento o decremento para "y"
 
endif
 
 
xh(end + 1) = x    #crecer la matriz "xh" en un elemento
 
yh(end + 1) = y    #crecer la matriz  "yh" un elemento    
 
 
endfor
 
 
 
xdesde = min(xh)       #Se buscan valores mas pequeños y mas grandes de la matrices
 
ydesde = min(yh)
 
xhasta = max(xh)
 
yhasta = max(yh)
 
 
minimo = min(xdesde, ydesde)
 
maximo = max(xhasta, yhasta)
 
 
 
anim = fopen("animar.plot", "w");
 
fprintf(anim, "plot 'pasos.dat' using (($1 == i) ? $2 : NaN):(($1 == i) ? $3 : NaN ) with points lt 1 pt 7 ps 3 notitle\n");
 
fprintf(anim, "i=i+1\n");
fprintf(anim, "if (i <= n) reread\n");
 
fclose(anim);
 
plot = fopen("correme.plot", "w");
 
fprintf(plot, "reset\n");
 
fprintf(plot, "set term gif animate delay 10\n");
 
fprintf(plot, "set output 'caminata_larga.gif'\n");
 
fprintf(plot, "set size square\n");
 
fprintf(plot, "set key off\n");
 
fprintf(plot, "i = 0\n");
 
fprintf(plot, "n = %d\n", n);
 
 
 
 
fprintf(plot, "set xrange [%d:%d]\n", minimo, maximo);
 
fprintf(plot, "set yrange [%d:%d]\n", minimo, maximo);
 
 
fprintf(plot, "load 'animar.plot'\n");
 
fprintf(plot, "set output\n");
 
fclose(plot);
 
 
datos = fopen("pasos.dat", "w");
 
for p = 1:(n+1)
 
fprintf(datos, "%d %d %d\n", p-1, xh(p), yh(p));
 
endfor
 
fclose(datos);




ANIMACION XYZ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
x = 0;
y = 0;
z = 0;
 
xh = [x];
 
yh = [y];
 
zh = [z];
 
n = 100;
 
 
 
 
for pasos = 1:n;   # repeticion
 
    cambio = 0;
 
endfor
 
   if (rand() > 0.5)          # condicion
 
cambio += 1;    # incremento
 
else
        cambio -= 1;    # decr
 
  endif
 
 
 
if (rand() > 0.5)          # condicion
 
x += cambio;    # incremento
 
    else
if (rand() > 0.5)
    y += cambio;    # decr
 
           else (rand() > 0.5)
           z += cambio;    # decr
 
endif
 
 
xh(end + 1) = x
yh(end + 1) = y
zh(end + 1) = z
 
 
xdesde = min(xh)
ydesde = min(yh)
zdesde = min(zh)
 
xhasta = max(xh)
 
yhasta = max(yh)
 
zhasta = max(zh);
 
minimo = min(xdesde, ydesde, zdesde) - 1
 
maximo = max(xhasta, yhasta, zhasta) + 1
 
 
 
anim = fopen("animar.plot", "w");
 
fprintf(anim, "plot 'pasos.dat' using (($1 == i) ? $2 : NaN):(($1 == i) ? $3 : NaN ) with points lt 1 pt 7 ps 3 notitle\n");
 
fprintf(anim, "i=i+1\n");
 
fprintf(anim, "if (i <= n) reread\n");
 
fclose(anim);
 
plot = fopen("correme.plot", "w");
 
fprintf(plot, "reset\n");
 
fprintf(plot, "set term gif animate delay 10\n");
 
fprintf(plot, "set output 'caminata_larga.gif'\n");
 
fprintf(plot, "set size square\n");
 
fprintf(plot, "set key off\n");
 
fprintf(plot, "i = 0\n");
 
fprintf(plot, "n = %d\n", n);
 
 
 
fprintf(plot, "set xrange [%d:%d]\n", minimo, maximo);
 
fprintf(plot, "set yrange [%d:%d]\n", minimo, maximo);
 
 
fprintf(plot, "set zrange [%d:%d]\n", minimo, maximo);
 
 
fprintf(plot, "load 'animate.gnu'\n");
 
fprintf(plot, "set output\n");
 
fclose(plot);
 
 
datos = fopen("pasos.dat", "w");
 
 
for p = 1:(n+1)
 
 fprintf(datos, "%d %d %d\n", p-1, xh(p), yh(p), zh(p));
 
endfor
fclose(datos);
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder