help-octave
[Top][All Lists]
Advanced

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

Re: Problem using fscanf


From: Utherr13
Subject: Re: Problem using fscanf
Date: Fri, 15 Apr 2011 02:37:00 -0700 (PDT)

I don't know how to use  load, help manual is ambiguous and not helping. I
want some examples.

 # Create test data file: 
   x = floor(100 * rand([100, 2]));  # create some data 
   f = fopen("data.txt", "w");       # error checking omitted 
   fprintf(f, "%d %d\n", x .');      # output data to file 
   fclose(f); 

whooo... hold one.. my data is not like that. It has 2,3 or 4 spaces between
first column and second.

The piece of code that you supplied to me only gets the first row.

Here's my complete code that doesn't work:

function y=dens_energy()
        % a = 3
        % besseli(0,3) = 4,8808
        f=fopen('sunspot.dat','r');
        a=zeros(100,2);
        for i=1:100
                z = fscanf(f,"%d",1);   %first column is useless
                a(i) = fscanf(f,"%d",1);
                disp(a(i));
        endfor
endfunction

a part of sunspot.dat: 

1701   11.0
1702   16.0
1703   23.0
1704   36.0
1705   58.0
1706   29.0
1707   20.0
1708   10.0
1709    8.0
1710    3.0
1711    0.0
1712    0.0
1713    2.0
1714   11.0

--
View this message in context: 
http://octave.1599824.n4.nabble.com/Problem-using-fscanf-tp3449262p3451645.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

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