[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Loading a matrix from ASCII file (avoiding scripting?)
From: |
Federico Zenith |
Subject: |
Re: Loading a matrix from ASCII file (avoiding scripting?) |
Date: |
Thu, 26 Aug 2004 16:36:45 +0200 |
User-agent: |
KMail/1.7 |
Alle 15:58, giovedì 26 agosto 2004, Mauro Casadei ha scritto:
> Hi all !
>
> I am a newcomer to Octave and to this list, so this is my chance to say hi
> to everybody ! :-)
Welcome!
> My problem is that I would like to be able to load into arrays and/or
> matrixes some plain, tab-delimited real/integers data.
>
> The file format would be something like the following:
>
> 0.0 1.0 3.0
> 1.0 2.5 5.1
I did something similar with a CSV file, I used gawk; there's a Windows
version of gawk here:
http://gnuwin32.sourceforge.net/packages/gawk.htm
For files created under Windows and moved to Linux, one should never forget
the following (broke my head on this for a day):
$ sed -i -e "s/\r\n/\n/g" yourFile.txt
(This to remove the Windows-style carriage returns, if you created the file in
Windows and want to use it in Linux|Unix)
The command in Linux (is probably the same or almost in Windows) is:
$ gawk '{print $1", "$2", "$3";"}' yourFile.txt > dataFile
Then, you should add the starting "mymatrix = [" and ending "] ;" to dataFile
manually (it should not be tragic). Then, the dataFile can be loaded in
Octave, and you can manipulate it from there.
Yes, it's scripting, but it seems quite simple to me to be worth trying.
Maybe someone knows a way of calling OS commands from the Octave shell, so it
can be implemented in a Octave function?
Cheers,
-Federico
pgpqSHJJ52Clw.pgp
Description: PGP signature