Search This Blog

Showing posts with label reading data files. Show all posts
Showing posts with label reading data files. Show all posts

Sunday, April 25, 2010

load data file with header lines in octave

When a data file contains some header lines before the actual data matrix, octave's dlmread function can be used to read the matrix of data and ignore the headers.

For example,

$cat input_data.m
col1 col2 col3
1, 2, 3
4, 5, 6
7, 8, 9
10, 11, 12

This file contains one header line and a 4x3 data matrix. To read it into octave, create a script called

$cat read_data.m
1;
A = dlmread("input_data.m", SEP=',', R0=1, C0=0);
A

$octave3.2 -qf
octave3.2:1> read_data
A =

1 2 3
4 5 6
7 8 9
10 11 12


For more information on dlmread function, use 'help dlmread' inside octave.

Tested using octave 3.2.4-3 on Debian stable (Lenny).

Followers