help-octave
[Top][All Lists]
Advanced

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

Re: Question on fscanf ....


From: Nicholas Jankowski
Subject: Re: Question on fscanf ....
Date: Sat, 21 Mar 2020 21:22:00 -0400

> My questions:
> 1.) is there  any way to circumvent the usage of Y and do some kind of
> [t,y]=fscanf(infile, "%*s %f %*lf %*f %*f %*f %*f %f %*f %*f", ??????);

I think you may prefer to use textscan.  This function respects the *
'ignore' flag and also stores outputs in separate elements of a cell
array.

Eg.,:

>> foo=fopen('data.dat');
>> bar = textscan(foo, "%*s %f %*f %*f %*f %*f %*f %f %*f %*f")
bar =
{
  [1,1] =

     0.00000
     0.25000
     0.50000
     0.75000
     1.00000
     1.25000
     1.50000
     1.75000
     2.00000
     2.25000

  [1,2] =

     0
     0
     0
     0
     0
     0
     0
     0
     0
     0

}

while these are in a single cell array, they are separately
addressable elements. It may be possible to get the 'C' style version
to work, but on a quick try I can only get it to read in the one line
at a time even if I play with \n's :
 >> foo = fopen('data.dat');
>> [bar1,bar2] = fscanf(foo, "%*s %f %*f %*f %*f %*f %*f %f %*f %*f", "C")
bar1 = 0
bar2 = 0
>> [bar1,bar2] = fscanf(foo, "%*s %f %*f %*f %*f %*f %*f %f %*f %*f", "C")
bar1 =  0.25000
bar2 = 0
>> [bar1,bar2] = fscanf(foo, "%*s %f %*f %*f %*f %*f %*f %f %*f %*f", "C")
bar1 =  0.50000
bar2 = 0
>> [bar1,bar2] = fscanf(foo, "%*s %f %*f %*f %*f %*f %*f %f %*f %*f", "C")
bar1 =  0.75000
bar2 = 0
>> [bar1,bar2] = fscanf(foo, "%*s %f %*f %*f %*f %*f %*f %f %*f %*f", "C")
bar1 =  1
bar2 = 0



reply via email to

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