[Top][All Lists]

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

textscan preserving all whitespace

From: rmales
Subject: textscan preserving all whitespace
Date: Thu, 11 Sep 2014 15:08:34 -0700 (PDT)

I apologize if this has been previously answered, I did search, it is clear
that there are many questions about textscan, but I did not see this
particular one (may be my ignorance).

I am using the experimental version of Octave for Windows 8 (v 3.8.2) with
the GUI, it works very well.

I have inherited some Matlab scripts that are used to create and parse
various Ascii files, and have been successful in converting them quite
easily to Octave.  However, I have one script that reads an entire ascii
file into an array and then has lots of parsing of that array that depends
upon preserving the whitespace, i.e. the exact number of spaces between
fields.   The input is processed through:

fid = fopen('ODOC');
tot = textscan(fid,'%s','delimiter','\n');

An example of the input that needs to be handled is: 
      3600.0     8.0000     2.1500     0.0000     0.2500     0.0000
      7200.0     8.0000     2.2500     0.0000     0.6830     0.0000
    10800.0     8.0000     2.3500     0.0000     0.9330     0.0000
    14400.0     8.0000     2.4500     0.0000     0.9330     0.0000
    18000.0     8.0000     2.5500     0.0000     0.6830     0.0000

When textscan processes this, the whitespace is crunched out so that there
is only a single whitespace character between fields.   This causes problems
for the rest of the script which is expecting fields to be in pre-defined
columns.  At present, I cannot change the format of the input Ascii file, I
am stuck with it.

Any suggestions on how to modfy the textscan command or use an alternative
method of reading the file that will preserve the spaces will be much
appreciated.   I am aware that Matlab textscan is not identical to Octave
textscan, was not expecting that to be the case.

Thank you all for this truly superior piece of software.

R. Males
Cincinnati, Ohio

View this message in context:
Sent from the Octave - General mailing list archive at

reply via email to

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