help-octave
[Top][All Lists]
Advanced

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

Re: reading xls file


From: Antonio Palestrini
Subject: Re: reading xls file
Date: Fri, 31 Aug 2007 23:57:42 +0200

Having the matrix of data in m,
I think it may be useful to use the following
simple function in order to assign quickly to the columns (if needed)
their original names, let's say "var1", "var2" and "var3",

function give_names(la,m)
#use:  give_names(labels, data);
#
#example:
#octave:11> la = [
#> "var1"
#> "var2"
#> "var3"];
#
#octave:12> m=rand(6,3)
#
#octave:13> give_names(la,m);
#octave:14> var1
#var1 =
#
#  0.70485
#  0.79600
#  0.58997
#  0.90910
#  0.62804
#  0.13553

  [n,c] = size(la);
   for i = 1:n,
    assignin ("base",la(i,:),m(:,i));
  end
endfunction


ciao
antonio


2007/8/31, John W. Eaton <address@hidden>:
On 31-Aug-2007, Antonio Palestrini wrote:

| 1) As said by Przemek*, *save your excel file, let's say data.xls file as
| csv format (data.csv)
|
| 2) open the file data.csv that in my example has 2 columns and 3 rows.
| It looks like
|
| ---- data.csv ---
| x;y
| 1;2
| 2;4
| 3;6
| --------------------------
|
| and delete the first row with labels, so remainin with
|
| ---- data.csv ---
| 1;2
| 2;4
| 3;6
| --------------------------
|
| 3) in octave write
|
| m = dlmread("data.csv",";");
|
| (there is also the function "csvread" that calls "dlmread")
| and you get the matrix of data stored in m.

The help for the current version of dlmread says:

  x = dlmread (filename, sep, row)
     Read the matrix x from a file, with columns separated by the
     character sep (default is ",").  NaN values are written as nan.
     The number of rows to skip before reading data is row (default is 0).

so instead of editing the file, I think you can just use

  m = dlmread ("data.csv", ";", 1);

jwe


reply via email to

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