• Publicidad

Matriz 3D con Octave

¿Apenas comienzas con Perl? En este foro podrás encontrar y hacer preguntas básicas de Perl con respuestas aptas a tu nivel.

Matriz 3D con Octave

Notapor lis » 2011-06-10 12:25 @559

Hola amigos del foro. Nuevamente recurro a ustedes para que me ayuden. Les cuento, tengo exactamente 347 archivos de 151x71 (extensión .dat). Tengo que concatenarlos en una matriz tridimensional por lo que quedaría así: 151x71x347. Utilizo el siguiente script de Perl "llamando" a Octave siguiendo el primer ejemplo de este link http://www.mathworks.com/products/matlab/demos.html?file=/products/demos/shipping/matlab/nddemo.html

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!/usr/bin/perl -w
  2.  
  3. my %hash;
  4. my $i = 1;
  5.  
  6. while ($data = </home/lis/Escritorio/QS/DATOS/u/*.dat>) {
  7.  
  8.     if ($i) {
  9.         $hash{$data} = $i;
  10.     }
  11.     $i++;
  12.  
  13. if ($hash{$data} >=2 ){
  14.  
  15. open (OC, ">archivo.m");
  16. print OC "clear all;\n";
  17. print OC "U = load ('/home/lis/Escritorio/QS/DATOS/u/200509011108_u.dat');\n";
  18. print OC "b = load ('$data');\n";
  19. print OC "U(:,:,$hash{$data}) = b;\n";
  20. print OC "save comp_U.mat U '-mat';\n";
  21. close(OC);
  22. system "(octave -q archivo.m)";
  23. }
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4


El primer arreglo, es decir 151x71x1, lo hace bien, pero en los otros solo quedan ceros. Por favor, ayúdenme a ver dónde está mi error. Muchísimas gracias.

Lis.
lis
Perlero nuevo
Perlero nuevo
 
Mensajes: 106
Registrado: 2008-05-27 21:43 @946

Publicidad

Re: Matriz 3D con Octave

Notapor explorer » 2011-06-10 17:08 @755

Primero, decir que existe PDL para realizar operaciones matemáticas desde el propio Perl, sin tener que usar otras herramientas externas, como Octave.

Segundo, no tengo ni idea de Octave, pero viendo el código, quizás sea así (no probado):

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4.  
  5. open (OC, ">archivo.m");
  6. print OC "clear all;\n";
  7.  
  8. my ($primero, @resto) = </home/lis/Escritorio/QS/DATOS/u/*.dat>;
  9.  
  10. print OC "U = load ('$primero');\n";
  11.  
  12. my $i = 2;
  13.  
  14. for my $fichero (@resto) {
  15.     print OC "b = load ('$fichero');\n";
  16.     print OC "U(:,:,$i) = b;\n";
  17.     $i++;
  18. }
  19.  
  20. print OC "save comp_U.mat U '-mat';\n";
  21. close(OC);
  22.  
  23. system "octave -q archivo.m";
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4


De todas maneras... Octave debería de tener alguna instrucción para realizar esto de forma automática...
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Matriz 3D con Octave

Notapor lis » 2011-06-11 12:54 @579

Nuevamente muchas gracias Explorer.
lis
Perlero nuevo
Perlero nuevo
 
Mensajes: 106
Registrado: 2008-05-27 21:43 @946


Volver a Básico

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 38 invitados

cron