help-octave
[Top][All Lists]
Advanced

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

Re: loading files with headers and footers


From: James Sherman Jr.
Subject: Re: loading files with headers and footers
Date: Mon, 22 Jun 2009 10:40:37 -0400

A rather klunky shot at it is something like:

data = "">
fid = fopen('filename');
line_string = fgetl(fid);   % reads one line of the file into a string
while (line_string != -1)   % makes sure its not eof
  [line_data, count] = sscanf(line_string, '%d %d');  % tries to parse string
  if (count == 2)   % if its successful (finds 2 integers)
    data = "" % append it to your data variable
  end
  line_string = fgetl(fid);
end
fclose(fid);

This is untested, so there may be some typos/logic fallacies, but I hope you get the idea.

Hope this helps.

James

On Mon, Jun 22, 2009 at 1:55 AM, Jonas Amhest <address@hidden> wrote:

Hi all, this is my first time posting to the Octave mailing list.

I'm not an absolute beginner but I'm a fairly novice programmer using a WinXP system with the latest Octave installed. I'm trying to load a .txt file that includes a header (not commented out), data, and a "footer" at the end of the columns like this:

testing header
jlkasjdsfjk
kj213
1    5
2    9
3    2
4    5
5    8
adfa

I know the load command doesn't work because it has a header and I've tried looking up and attempting to make sscanf, scanf, fscanf, fopen etc and can't get it to work at all. I keep getting errors saying that line is undefined at column x and row y where there isn't even any data. How can I skip the three first lines of the header above, read in the two data columns, and then skip the last line?

Thank you so much!

-Mike





_______________________________________________
Help-octave mailing list
address@hidden
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave


reply via email to

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