help-octave
[Top][All Lists]
Advanced

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

IO formatted without discarding initial whitespace?


From: OctIce
Subject: IO formatted without discarding initial whitespace?
Date: Tue, 15 Jul 2008 08:29:01 -0700 (PDT)

I wonder if there is an easy way not to disregard initial whitespace in
formated IO with fscanf.
My problem:
I have an fixed format ascii file, where each number has a certain space, 2
character, 3 characters, etc.
lets take an easy example, 5 numbers per line with a fixed width of
3,3,2,2,3 characters:
1112223344555
   1   2  3  4   5
   1222  344   5
The result I want to have is
111,222,33,44,555
1,2,3,4,5
1,222,3,44,5 
but as fscanf discards initial whitespace i get:
q=fscanf(fid,'%3d%3d%2d%2d%3d',[5,inf])
q =
  111.00    1.00  122.00
  222.00    2.00    2.00
   33.00    3.00   34.00
   44.00    4.00    4.00
  555.00    5.00    5.00
I can read it with a loop over all lines, reading it as string and then
read the substrings. E.G:
s=fgetl(fid);
V1=str2num(S(1:3));V2=str2num(S(4:6));
V3=str2num(S(7:8));V4=str2num(S(9:10));
V5=str2num(S(11:13));
This is a bit cumbersome, and having files with more then 400000 lines takes
a long time.

Does anyone have an idea how to better read this data?

Note th the used data format: This format was quite common in "older days".
As it is ascii it is easily portable between different computers and the
form is compact to save space. It is also very easy to read and write in
Fortan. 




-- 
View this message in context: 
http://www.nabble.com/IO-formatted-without-discarding-initial-whitespace--tp18468100p18468100.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

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