help-octave
[Top][All Lists]
Advanced

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

Re: CSVs, .DATs


From: Mike Miller
Subject: Re: CSVs, .DATs
Date: Wed, 2 May 2012 08:18:23 -0400

On Wed, May 2, 2012 at 7:03 AM, monkeyboy <address@hidden> wrote:
> Hi
>
> I'm very new to Octave and open source unix stuff so please excuse my
> ignorance. I've been struggling with a problem for a while now.
>
> I'm working on a thesis experiment in which I wish to plot a 3d
> representation of 4 streams of 20,000+ data points with each of the four
> points along the z-axis.
>
> The data comes from a Campbell Scientific CR800 datalogger. The data files
> from the logger include a timestamp, record number and then a column for
> each of 18 sensors. I need to perform calculations on 8 pairs of the sensor
> data. I will also have to discard some of the data (probably just from the
> beginning)
>
> Having not known about Octave, gnuplot and 3d plotting at the outset I have
> committed (apparently) the crime of using Excel to analyse and organise
> data.
>
> I'm running an Intel Macbook pro with OS 10.6.8 and Octave 3.4 with the
> Gnuplot that came with it.
>
> My problem is, as you've probably guessed, that I can't get Octave or
> Gnuplot to read the data from excel no matter which way I try to delimit it.
> I've tried with very simple test files a number of ways and get a variety of
> results none of which are accurate.
>
> I have just tried CSVREADing the data direct from the datalogger and it does
> at least read it but it reads all the text headers as zeros and does the
> same crucially with the timestamp.
>
> The .dats produced by the datalogger are comma seperated.
>
> I have read a couple of threads which have helped up to a point but I'm
> stuck now.
>
> Can anyone offer any help in a language I may be able to understand.

The csvread function can take in an already opened file descriptor.
You can open the file, read the header lines into separate variables,
handle them specially, or throw them away, and then invoke csvread to
grab the rest of the data.  Example:

example.csv:
ignore this line
and this line
Wed, 02 May 2012 08:12:46 -0400
0,1,2,3,4,5,6,7,8,9
0,1,2,3,4,5,6,7,8,9
0,1,2,3,4,5,6,7,8,9
0,1,2,3,4,5,6,7,8,9


octave:1> f = fopen('example.csv');
octave:2> h1 = fgets(f)
h1 = ignore this line

octave:3> h2 = fgets(f)
h2 = and this line

octave:4> timestamp = fgets(f)
timestamp = Wed, 02 May 2012 08:12:46 -0400

octave:5> data = csvread (f)
data =

   0   1   2   3   4   5   6   7   8   9
   0   1   2   3   4   5   6   7   8   9
   0   1   2   3   4   5   6   7   8   9
   0   1   2   3   4   5   6   7   8   9

HTH.
-- 
mike


reply via email to

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