help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Tip for loading Excel Spreadsheet into Octave on Mac


From: John W. Eaton
Subject: Tip for loading Excel Spreadsheet into Octave on Mac
Date: Wed, 4 Feb 2004 21:52:22 -0600

On  4-Feb-2004, Henry F. Mollet <address@hidden> wrote:

| There may be more sophisticated ways to get an Excel Spreadsheet into Octave
| on Mac but this works for me and I don't have to explicitly change the
| carriage return (\r) of Mac OS into newline (\n) of Unix. I suggest that
| this is suitable for medium sized data matrices, which would be cumbersome
| to enter in octave at the command line prompt but not that large that a
| spreadsheet wouldn't really work either.
| 
| Copy your spreadsheet (I'm using Excel) and paste it into BBEdit Lite 6.1
| for OS X. BBEdit has a Unix save/save as option. Octave will load this file:
| 
| octave:83> load Test&testfile
| octave:84> whos
| *** local user variables:
| prot  type                       rows   cols  name
| ====  ====                       ====   ====  ====
|  rwd  matrix                       39      7  Test_testfile
| Octave even takes care of the "&" in the filename and renames the matrix but
| it cannot handle a space.
| 
| Now the name of the matrix "Test_testfile" can be changed to say
| "InputMatrix" (so it will the same as in the script which will use the file)
| octave:92> InputMatrix=Test_testfile
| 
| Now the file can be saved with the same name *in octave*
| octave:94> save Test&testfile InputMatrix
| 
| BBEdit will even automatically amend the file with
| # Created by Octave 2.1.46, Wed Feb 04 18:50:05 2004 PST
| <address@hidden>
| # name: InputMatrix
| # type: matrix
| # rows: 39
| # columns: 7
| Henry

If all you have is numeric data with no missing values, then Octave's
load command should be able to read it if you save it in CSV file.
For example, I loaded the following data

  1,2,3,4
5,6,7,8

stored in a file called "foo bar" with no problem using the command

  x = load ("foo bar");

with Octave 2.1.50 (running on a Debian x86 system, but I don't think
that detail matters).  The file has only CR and no NL characters in
it.  The result of loading the file is the matrix

  x =

    1  2  3  4
    5  6  7  8

Note that this method also handles filenames with spaces and allows you to
rename the data to whatever variable name you would like.

Does this not work for you on OS X?  Can Excel save data in this
format, or does it insist on quoting fields in some way, even when you
save numeric data in CSV format?

jwe



-------------------------------------------------------------
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
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]