[Top][All Lists]

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

Re: Plotting data from a file containing comments as first lines

From: Jonathan Stickel
Subject: Re: Plotting data from a file containing comments as first lines
Date: Tue, 08 Jun 2004 09:17:51 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040326

address@hidden wrote:
Hi, my problem: I would like to plot the data contained in a file beginning with comments... The file looks like: blabla1 blabla2 dsfsdsdfd 1 3 -5 6 0 8 1 8 Of course it would be easy if there was no comments at the beginning, I would just load the data typing load data and then plot it with plot data Is there a way to tell Matlab (or Octave, because I work a lot with Octave) to ignore the first 3 or 4 lines ? There must be one, but I can t find it...

For this, I think you must use the low-level fopen, fscanf type commands. Pasted below is a function I just wrote that I think will satisfy your needs.


function data=datareadwh(filename,nhl,nc)
  %%  Read data from a file, skipping the first nhl lines
  %%  (header lines).  nc is the number of columns the data
  %%  is expected to be in.

  %%  author:  Jonathan Stickel
  %%  created:  8 June 2004
  %%  modified:  8 June 2004

  [fid,msg] = fopen (filename, "r");

  for i=1:nhl

  [data,count] = fscanf (fid, "%f");

  if ( nr-floor(nr) )
disp("warning: data read is not an integer multiple of the specified number of columns;")
    disp("returning data in a single column")
    data=reshape (data,nc,nr)';


Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

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