help-octave
[Top][All Lists]
Advanced

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

Re: IO formatted without discarding initial whitespace?


From: Rob Mahurin
Subject: Re: IO formatted without discarding initial whitespace?
Date: Wed, 16 Jul 2008 11:52:10 -0400

On Jul 15, 2008, at 11:29 AM, OctIce wrote:
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

If each line is a fixed width, you can use fread() to load (big chunks of) the file into memory as a matrix of characters. You can then feed slices of this array to char() and str2num() to produce arrays of numbers, without line-by-line looping.

For what it's worth, your or my email client mangled the formatting on your example.

Cheers,
Rob

--
Rob Mahurin
Dept. of Physics & Astronomy
University of Tennessee         phone: 865 207 2594
Knoxville, TN 37996             email: address@hidden



reply via email to

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