From help-octave-request at bevo dot che dot wisc dot edu Thu Jul 4 12:52:29 2002 Subject: Re: reading matrix of unknown dimensions from file. From: Arno Peters To: help-octave at bevo dot che dot wisc dot edu Date: Thu, 4 Jul 2002 19:51:09 +0200 --vkogqOf2sHV7VnPd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Jul 04, 2002 at 10:37:17AM -0500, Mike Miller wrote: > By the way, is there a way to load a file that looks like this... > > 1 2 3 4 > 1 2 > 1 2 3 4 5 > 1 2 3 > > ...and have Octave automatically pad with zeros to produce a matrix in > Octave that looks like this? > > 1 2 3 4 0 > 1 2 0 0 0 > 1 2 3 4 5 > 1 2 3 0 0 Preprocess you file with the attached perl script. Greetings, -- Arno --vkogqOf2sHV7VnPd Content-Type: application/x-perl Content-Disposition: attachment; filename="pad.pl" Content-Transfer-Encoding: quoted-printable #!/usr/bin/perl -w=0A#=0A# Usage: ./pad.pl columns=0A#=0A# Pads the input w= ith zeros to the desired number of columns.=0A=0Aif (scalar( at ARGV) !=3D 1) = {=0A print STDERR "Usage: pad.pl columns\n";=0A exit 1;=0A}=0A=0A$cols = =3D shift( at ARGV);=0Awhile (<>) {=0A chop;=0A @array =3D split(/\s+/);=0A = $col =3D scalar( at array);=0A if ($col > $cols) {=0A die "Found $col col= umns in the input, cannot pad to $cols columns";=0A }=0A print;=0A while= ($col < $cols) {=0A print " 0";=0A $col++;=0A }=0A print "\n";=0A}= =0A --vkogqOf2sHV7VnPd-- ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------